Hello Phil, Tuesday, July 8, 2003, 11:11:49 PM, you wrote:
PD> Is there a function that can be used to retrieve the name of a statically PD> called child class from within an inherited method? debug_backtrace() works PD> for this purpose, but I've seen people say that it is slow. Consider the PD> example code below. Is this a planned feature for PHP 5, or could this PD> possibly make it into 4.x? What options do I have? PD> <? PD> class a PD> { PD> function test_backtrace() PD> { PD> $bt = debug_backtrace(); PD> echo "class pre: ".__CLASS__."\n"; PD> echo "class bt: ".$bt[0]["class"]."\n"; PD> echo "class get_class: ".get_class($this)."\n"; PD> } PD> } PD> class b extends a PD> { PD> } PD> echo "** static: \n"; PD> b::test_backtrace(); PD> $b = new b(); PD> echo "** object: \n"; $b->>test_backtrace(); ?>> PD> Output Looks Like: PD> ** static: PD> class pre: a PD> class bt: b PD> class get_class: PD> ** object: PD> class pre: a PD> class bt: b PD> class get_class: b - the method is defined in class a so pre is correct - backtrace @[0] sees the top caller class that's b that's correct - get_class($var) sees the class of the variable. In you static case that is NULL which doesn't have a class and in your object case that's b. Therfore this is also correct. Everything show is correct so far. The only problem is that test_backtrace() could be called static without being defined as such. PD> Perhaps get_class() could return the expected class name when PD> called without arguements? This is nonsense. NULL does not have a class type. Best regards, Marcus mailto:[EMAIL PROTECTED] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php