标签: runkit

PHP - 用于拦截方法调用的runkit的替代方法

我有一些非常不友好的测试代码(至少可以说是我需要测试的).不幸的是,重构不是一种选择.我必须按原样测试代码,而不必更改它.

为此,我考虑拦截函数调用并动态更改它们的作用,以便我可以运行我的测试,因为我需要一些函数和方法来返回已知值,我需要其他人发出请求,连接到数据库等等,停止这样做,并返回我需要他们返回的东西.有没有办法做到这一点没有runkit_method_redefine(),这最好不是"实验",仍然保持?也许是runkit的替代品?也许更好的方式?

编辑:如果我需要该功能,将使用PHPUnit的测试双精度和PHP 5.3.2的功能来使私有方法可访问.

php reflection runkit

5
推荐指数
1
解决办法
4264
查看次数

如何重命名或覆盖php功能?

我如何用runkit重新定义php中的函数?

$helloWorld = 'echo "Call require_once";';
runkit_function_redefine('require_once', '$word', $helloWorld);
require_once("abc.php");
Run Code Online (Sandbox Code Playgroud)

我在php.ini中找到了

runkit.internal_override=1
Run Code Online (Sandbox Code Playgroud)

当我跑,它显示:

Warning: runkit_function_redefine() [function.runkit-function-redefine]: require_once() not found in hhd_debug.php on line 2

Warning: require_once(abc.php) [function.require-once]: failed to open stream: No such file or directory in hhd_debug.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'abc.php' (include_path='.;xampp\php\PEAR') in hhd_debug.php on line 3
Run Code Online (Sandbox Code Playgroud)

我怎么能解决它?请帮我!

php runkit

2
推荐指数
1
解决办法
808
查看次数

标签 统计

php ×2

runkit ×2

reflection ×1