php - Using backtrace_debug to determine caller class and caller method for the function. Am I doing it wrong? -
i have parent class , children class. in parent class define function f() , want print in name of children class extended parent class , name of children method called function. that.
abstract class parentclass { public function f() { $backtrace = debug_backtrace(); echo "class: " . $backtrace[1]['class']) . "\n"; echo "function: " . $backtrace[1]['function']; } } class childrenclass extends parentclass { public function some_func() { $this->f(); } } $o = new childrenclass; $o->some_func();
and correctly outputs me:
class: childrenclass function: some_func
the question is: solution appropriate or there better way achieve this? tried use __class__
, __function__
gives me classname , function name of parent class.
if print out $backtrace var might see goes more classes
echo "debug:<pre>".print_r($backtrace,true)."</pre><br />";
so calling
$backtrace[1]['class']
will work might make dynamic. like:
// loop, pseudo-code $i = 0; $backtrace[$i]['class'] $i++;
Comments
Post a Comment