将占位符(空对象)分配给类属性的正确方法是什么?
示例:
class something {
public $my_object = object; // ???
public function __construct() {
//create some object, via some function...
$this->my_object = $some_object;
}
}
答案 0 :(得分:3)
这样的事情可能是:
class something {
public $my_object;
public function __construct() {
$some_object = new StdClass();
$this->my_object = $some_object;
}
}
测试:
$obj = new something();
var_dump($obj);
输出:
object(something)#1 (1) {
["my_object"]=>
object(stdClass)#2 (0) {
}
}