考虑此示例代码为什么我的PHP类没有保存它的属性?
<?php
class MyAwesomeClass {
public $myawesomeproperty = 'test';
public function __construct() {
$self = new stdClass();
$self->myawesomeproperty = "hello guys!";
}
}
$test_obj = new MyAwesomeClass();
echo '<pre>';
var_export($test_obj);
echo '</pre>';
?>
它应该这样var_export显示“myawesomeproperty”设置为一个新的字符串“好家伙!”在输出中。
我真的开始是
MyAwesomeClass::__set_state(array(
'myawesomeproperty' => 'test',
))
显然,构造函数不保存任何实际的对象。
这是怎么发生的?我错过了什么?
不要使用“短打开标签”,他们早已过时,非常服务器专用。总是用'<?php'打开你的代码。 – miken32
你为什么这样做'$ self = new stdClass();'? – AbraCadaver