我有以下的PHP代碼(?):從子類中調用__construct靜態
<?php
class ParentClass {
public $table_name;
function __construct() {
$this->table_name = strtolower(__CLASS__);
}
}
class ChildClass extends ParentClass {
function __construct() {
parent::__construct();
//And I also want to put here other codes
}
}
$parent = new ParentClass();
$child = new ChildClass();
echo $parent->table_name . "<br />" . $child->table_name;
?>
結果是
parentclass
parentclass
但是我想這是
parentclass
childclass
如何我能達到它嗎? 後期靜態綁定可以解決我的問題,但它當然不能被靜態調用。 http://php.net/manual/en/language.oop5.late-static-bindings.php
我可以知道你想達到什麼樣的? –
是的,請重新閱讀我上面的問題。 – user3210615