How to get caller method name

So, I am looking for how to get the name of the caller method. I have never seen him, and I do not know if he exists.

Example:

<?php 
  class father {
    public function db_select(){
      echo method that call me;
    }
  }

  class plugin extends father {
    public function select_plugin(){
      $query = $this->db_select();
    }
   }

?>

All I want to do is write the name of the method that calls the method db_select()inside db_select().

+4
source share
2 answers

I think debug_backtrace can do the trick.

It gives you the inverse function call function. Observe this result, then you will need to figure out how to get the desired function name. But there is information.

<?php 
  class father {
    public function db_select(){
      echo debug_backtrace()[1]['function'];
      print_r(debug_backtrace());     
    }
  }

  class plugin extends father {
    public function select_plugin(){
      $query = $this->db_select();
    }
   }

?>
+4
source

Disclaimer: I do not use PHP.

@Jean Victor - , () () PHP.

" (# Visual Basic)"

" Caller Info, . , . , ".

, PHP.

-, .NET, , PHP, System.Runtime.CompilerServices Namespace, " , , ".

: kludge ( , ).

, ALL - GUID.

# id of  myFunctionABC f4f866c7728040a6bf22c7600c64a7ee
function myFunctionABC ($whoCalledMe) {

# Note:  myFunctionABC would use the value passed
#        via $whoCalledMe in error messages.



# BUT if from within myFuntionABC some other
# function is called, the above GUID would be used:
#
#     foo("f4f866c7728040a6bf22c7600c64a7ee")

}

, , .
FWIW


, debug_backtrace.
debug_backtrace .NET.
end edit.

0

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


All Articles