我遇到了“调用非对象上的成员函数”的问题 - 错误。字段 $other_class 不可设置用于将来的操作。如何填充和使用对象 $other_class?谢谢。
$myclass = new MyClass;
$other_class = $myclass -> GetOther_Class();
var_dump($other_class); //Works!
echo $other_class; //Call to a member function on a non-object - Error
class MyClass
{
private $other_class;
function __construct()
{
$other_class = new Other_Class; //Fill $other_class
//I tried also
//$this -> other_class = new Other_Class;
}
public function GetOther_Class()
{
return $other_class;
}
private function Generate()
{
$other_class -> SetTitle ("Hello");
}
public function __toString()
{
$this->Generate();
}
}