ID: 34804 User updated by: toomuchphp-phpbugs at yahoo dot com -Summary: More information about class methods Reported By: toomuchphp-phpbugs at yahoo dot com Status: Open Bug Type: Feature/Change Request Operating System: Any -PHP Version: 5.1.0RC1 +PHP Version: 5.x New Comment:
So ... now that I have learned C and played around with the 5.1.4 source for a couple of days, I've discovered it's not really possible to get information about the calling context using matic constants. In which case, a function named something like 'get_static_child()' would suffice. I am still trying to figure out how to find the name of the child class in the Zend hive of structs (if it is actually stored somewhere). :-S Previous Comments: ------------------------------------------------------------------------ [2006-01-11 21:35:07] kvesteri at cc dot hut dot fi There should definetly be atleast constant __INHERITED_BY__. This new constant would allow many wonderful things like a generic singleton class and an efficient implementation of the martin fowler's Active Record pattern. ------------------------------------------------------------------------ [2005-10-10 10:12:46] toomuchphp-phpbugs at yahoo dot com Description: ------------ Inside any class method, there are as many as 3 related class and it would be useful to have all of them as magic constants, and also in the debug_backtrace function. Currently only __CLASS__ is available (the name of the direct owner of the method). It would be good to know the name of the child class (if the method was called as part of a child class), and the name of the calling class if the method was called statically (the same as get_class($this) inside a static method). This information would be most useful in the debug_backtrace() array. debug_backtrace() was recently modified to report the direct owner class name rather than the inheriting class' name (see bug #30828) but it would really be more helpful in debugging to have all three possible class names available. Reproduce code: --------------- class A { function A() { echo 'direct owner: '.__CLASS__."\n"; echo 'called as part of: '.__INHERITED_BY__."\n"; echo 'called by instance of: '.__STATIC_CALLER__."\n"; } } class B extends A { } class C { function __construct() { B::A(); } } new C(); Expected result: ---------------- direct owner: A called as part of: B called by instance of: C ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34804&edit=1