0
我嘗試使用函數創建基本類。一旦創建了該類的一個實例new BaseClass("hello")
,那麼構造函數會將該參數保存到一個變量中。 ->ret_text()
應該返回這個變量,但它不起作用。錯誤是:unexpected T_OBJECT_OPERATOR
在類中使用構造函數和公共函數
class BaseClass {
var $txt;
function __construct($text) {
$txt = $text;
}
public function ret_text() {
return $txt;
}
}
echo (new BaseClass("hello"))->ret_text();