So, I'm looking for how to get the caller's method name. I never saw it and I don't know if it 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 is to write the method's name that calls db_select()
method, inside db_select()
.
I think debug_backtrace could do the trick.
It gives you a backtrace of a function call. Observe this result then you'll have to figure out how to grab the function name you want. But the information is there.
<?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();
}
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With