为什么 PHP OOP 程序没有输出?
<?php
class TrimPHP_Strings {
public $str;
public function Apply() {
return $this->str;
}
function __constructor($str) {
$this->str = $str;
}
}
function Strings($str) {
$obj = new TrimPHP_Strings($str);
return $obj;
}
?>
<?php
echo Strings("My String")->Apply();
?>
我不明白为什么上面的代码不起作用?我希望它输出 My String
但它只是输出一个空白页。
<?php
class TrimPHP_Strings {
public $str;
public function Apply() {
return $this->str;
}
function __constructor($str) {
$this->str = $str;
}
}
function Strings($str) {
$obj = new TrimPHP_Strings($str);
return $obj;
}
?>
<?php
echo Strings("My String")->Apply();
?>
I can not understand why the above code doesn't work? I expect it to output My String
but it simply outputs a blank page.
构造函数的正确名称是
__construct
,而不是__constructor
The proper name for the constructor is
__construct
, not__constructor