我在这里读到:http://osdir.com/ml/php.phpunit.user/2008-05/msg00009.html使用runkit可能会改变更改类final
的行为 - 我只是看不清楚如何。
编辑:不要-1我请,我检查了runkit_import()函数,http://php.net/manual/en/runkit.constants.php仍然无法找到方法
答案 0 :(得分:1)
它的用途有限。举例说明:
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
类编写一个Decorator(或从源中删除final
)。