最后一行回显不起作用。我如何引用 id 或昵称?我收到的错误是 Call to a member function on a non-object in. dsaojfj kjsaoj oisjao jpods jop djopa jpaos jdo jpoajsoj op pa poj opdjaojs pojap jposajop jopajojdopsajodjop jaop jpoj ojdojpsoaj ojod jopajsdodjaospjop d add details ....srr。
<?php
class test{
public $id;
public $nickname;
function __construct($id_, $nickname_) {
$this->id = $id_;
$this->nickname = $nickname_;
}
public function setId($id_){
$this->id = $id_;
}
public function setNickname($nickname_){
$this->nickname = $nickname_;
}
public function getId(){
return $this->id;
}
public function getNickname(){
return $this->nickname;
}
}
class InfoTest{
public $tests = array();
public $number;
function __construct() {
$this->number = 0;
}
public function addTest(test $test_){
$this->number++;
$this->tests[$number] = $test_;
}
public function numberTests(){
return $this->number;
}
}
$r = new test(1,2);
$cc = new InfoTest;
$cc->addTest($r);
echo $cc->tests[1]->getId();
?>