繁体   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