最後の行のエコーが機能しません。IDやニックネームはどのように参照できますか?私が受け取ったエラーは、非オブジェクトのメンバー関数への呼び出しです。
<?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();
?>