PHP - function call recognition

I’m thinking about how to find where any function was called from. The problem is that I need to find where PHP calls the function mail(). One of the methods will be used register_tick_function(), but I will need to open each file and check what is on each line. The project is huge, it will take a lot of time to analyze each file in PHP. Any other way? Or a function override option mail()?

+3
source share
5 answers

To override the built-in mail function, look at override_function , which is part of the PHP Extended Debugger PECL Extension - then you can use debug_backtrace to find out the caller more ...

//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);
+6
source

You can check the stack trace debug_backtrace(). This will contain information about the calling method / function among others. See the manual for examples.

To add behavior to an existing function, wrap the function in your own function or class, and then call it instead of the built-in function.

, runkit. runkit_redefine_function() ( APD, ).

, mail(), . , IDE. Eclipse, Zend Studio Netbeans , , .

+3

, , "mail\s (" "my_mail (", my_mail .

+2

"mail ("?

+1

, ?

, jEdit, (* ?

Or do you really need to know the line numbers at runtime? I can’t imagine what you are actually doing.

0
source

Source: https://habr.com/ru/post/1728429/


All Articles