我是新來OOP,我一直在這個例子中,但我似乎無法擺脫這種錯誤PHP後期靜態綁定revieve錯誤期待T_FUNCTION
Parse error: syntax error, unexpected ';', expecting T_FUNCTION in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\...\php_late_static_bindings.php on line 16
我試圖執行後續的代碼:
abstract class father {
protected $lastname="";
protected $gender="";
function __construct($sLastName){
$this->lastname = $sLastName;
}
abstract function getFullName();
public static function create($sFirstName,$sLastName){
return new self($sFirstName,$sLastName);
};
}
class boy extends father{
protected $firstname="";
function __construct($sFirstName,$sLastName){
parent::__construct($sLastName);
$this->firstname = $sFirstName;
}
function getFullName(){
return("Mr. ".$this->firstname." ".$this->lastname."<br />");
}
}
class girl extends father{
protected $firstname="";
function __construct($sFirstName,$sLastName){
parent::__construct($sLastName);
$this->firstname = $sFirstName;
}
function getFullName(){
return("Ms. ".$this->firstname." ".$this->lastname."<br />");
}
}
$oBoy = boy::create("John", "Doe");
print($oBoy->getFullName());
有沒有人有任何想法? $ oGirl = girl :: create(「Jane」,「Doe」); print($ oGirl-> getFullName());
'return new static' should be the call。因爲否則它會嘗試實例化抽象類(這將失敗)......但第16行是什麼? – ircmaxell 2011-04-25 19:29:14