Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the name and details of function being called by PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 250
    Comment on it

    Hello Reader's! if you want to get the name of function and method being called, Then by using PHP you can do this as explain below:- Lets's see the example as below:- We use the info provided by a php exception, it's an elegant solution:

    function GetCallingMethodName(){
        $e = new Exception();
        $trace = $e->getTrace();
        //position 0 would be the line that called this function so we ignore it
        $last_call = $trace[1];
        print_r($last_call);
    }
    
    function firstCall($a, $b){
        theCall($a, $b);
    }
    
    function theCall($a, $b){
        GetCallingMethodName();
    }
    
    firstCall('lucia', 'php');
    

    And the ouptput is:-

    Array
    (
        [file] => /home/lufigueroa/Desktop/test.php
        [line] => 12
        [function] => theCall
        [args] => Array
            (
                [0] => lucia
                [1] => php
            )
    
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: