dimanche 1 mars 2015

In PHP is it possible to reverse traverse a Traversable class with debug_backtrace?

If one were to extend a built in class that implements Traversable would it be possible to use debug_backtrace to find out where the whole thing starts.


For example if I have



$foo->bar->baz->biz->bon->bop->bob();


and in the bob method of bop I make use of debug_backtrace is there a way to get a reference to $foo? (And what is that way?)


If so is this even the most elegant or efficient way to do that?


I've tried looking at the debug_backtrace php.net page and I am still not the clear how to really use this function.


Update #1:


There does seem to be some debate on if debug_backtrace should be left in production code. PHP debug_backtrace in production code?


Of course part of this is the issue of coupling, should a called object have knowledge of the object calling it?


Aucun commentaire:

Enregistrer un commentaire