gpt4 book ai didi

PHP - 识别函数何时被调用

转载 作者:可可西里 更新时间:2023-11-01 00:01:38 25 4
gpt4 key购买 nike

我正在考虑如何找到调用任何函数的位置。问题是我需要找到 PHP 调用 mail() 函数的位置。一种方法是使用 register_tick_function(),但我需要打开每个文件并检查每一行的内容。这个项目很大,用PHP解析每个文件需要很长时间。还有别的办法吗?或者选择如何覆盖 mail() 函数?

最佳答案

要覆盖内置邮件功能,请查看 override_function这是 Advanced PHP Debugger PECL extension 的一部分- 然后你可以使用 debug_backtrace找出来电者的详细信息...

//define code to override mail function (note I've used php5.3 nowdoc syntax to avoid 
//the need to escape the dollar symbols!!
$code=<<<'CODE'
$trace=debug_backtrace();
$caller=array_shift($trace);

echo 'mail() called by '.$caller['function']
if (isset($caller['class']))
echo 'in '.$caller['class'];
CODE;

//install override
override_function('mail', '$to,$subject,$msg,$hdrs,$params', $code);

关于PHP - 识别函数何时被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2063126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com