簡體   English   中英

php runkit_import和最終課程

[英]Php runkit_import and final classes

我在這里閱讀: http ://osdir.com/ml/php.phpunit.user/2008-05/msg00009.html更改類的final行為可能會通過Runkit進行更改-我只是不知道怎么做。

編輯:請不要-1我,我檢查了runkit_import()函數,而且http://php.net/manual/en/runkit.constants.php仍然找不到方法

用途有限。 插圖:

final class Foo {
    protected $var = '456';
    function doSomething(){
        return '123';
    }
    function getVar(){
        return $this->var;
    }
}

class Bar {

}
runkit_class_adopt('Bar','Foo');

$d = new Bar();
var_dumP($d->doSomething());
//string(3) "123"
var_dumP($d->getVar());
//PHP Notice:  Undefined property: Bar::$var in .... on line 10
//NULL

你通常是更好的寫一個裝飾為final (或移除類final從源頭)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM