Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get path of function being used in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 286
    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 here we are using 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($_call);
    }
    
    function firstCall($a, $b){
      theCall($a, $b);
    }
    
    function theCall($a, $b){
      GetCallingMethodName();
    }
    
    firstCall('lucia', 'php');

    And the output will be as is:-

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

    In the array key 'function' will tell the function and in the key 'args' will tell the number of args or param being passed to this function.

 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: