简体   繁体   English

php runkit_import和最终课程

[英]Php runkit_import and final classes

I read here: http://osdir.com/ml/php.phpunit.user/2008-05/msg00009.html that changing a class final behaviour may be changed with runkit - I just cant see the way how. 我在这里阅读: http ://osdir.com/ml/php.phpunit.user/2008-05/msg00009.html更改类的final行为可能会通过Runkit进行更改-我只是不知道怎么做。

EDIT: dont -1 me pls, I checked the runkit_import() function and also the http://php.net/manual/en/runkit.constants.php still cant find the way 编辑:请不要-1我,我检查了runkit_import()函数,而且http://php.net/manual/en/runkit.constants.php仍然找不到方法

It's of... limited use. 用途有限。 An illustration: 插图:

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

You're usually better of writing a Decorator for final classes (or removing the final from the source). 你通常是更好的写一个装饰为final (或移除类final从源头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM