为什么 PHP 认为我想将该对象转换为字符串?
class Class1 {}
class Class2 {
function __construct( Class1 $class1Obj) {
$this->$class1Obj = $class1Obj; // -> Catchable fatal error: Object of class Class1 could not be converted to string
}
}
$class1Obj = new Class1();
$class2Obj = new Class2($class1Obj);
最佳答案
它是一个额外的$
吗?那会更好:
$this->class1Obj = $class1Obj;
关于php - 分配中的 "Object of class ... could not be converted to string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17457611/