我想知道是否可以在 PHP 运行时添加新的类数据成员?
Yes.
$prop = 'newname'; $obj->$prop = 42;
会做同样的事情:
$obj->newname = 42;
如果 $obj 尚不存在,则任一者都会将“newname”添加为属性。