使用PHP 7.0.17,在class
构造函数中设置属性对我无效。未在类中调用的PHP构造函数
class T
{
public $property;
function __contruct()
{
$this->property = "Test";
print "I'm called :)";
}
}
$t1 = new T();
print_r($t1);
t.php
当我运行通过php t.php
的代码,我得到:
T Object
(
[property] =>
)
很显然,我希望I'm called :)
印刷到终端和属性设置到Test
。如图所示in this example on php.net
这是一个非常简单的问题,但我真的需要另一双眼睛。
'$这个 - > property',不'$此 - > $ property' –
'$此 - > $ property' - >注意你有'$'两次。这是打算吗? – Mjh
另外,'__construct',而不是'__contruct' – roberto06