我在这里读到:http://osdir.com/ml/php.phpunit.user/2008-05/msg00009.html,改变一个类的final行为可以用runkit来改变--我就是看不出该怎么做。
编辑:请不要这样做,我检查了runkit_import()函数,但http://php.net/manual/en/runkit.constants.php仍然找不到方法
发布于 2014-11-23 20:35:57
这是..。有限的使用。下面是一个示例:
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 )。
https://stackoverflow.com/questions/27088852
复制相似问题