Inheritance and Static Methods

From: Date: Tue, 08 Jul 2003 21:11:49 +0000
Subject: Inheritance and Static Methods
Groups: php.internals 
Request: Send a blank email to internals+get-3309@lists.php.net to get a copy of this message
Is there a function that can be used to retrieve the name of a statically called child class from within an inherited method? debug_backtrace() works for this purpose, but I've seen people say that it is slow. Consider the example code below. Is this a planned feature for PHP 5, or could this possibly make it into 4.x? What options do I have? <? class a { function test_backtrace() { $bt = debug_backtrace(); echo "class pre: ".__CLASS__."\n"; echo "class bt: ".$bt[0]["class"]."\n"; echo "class get_class: ".get_class($this)."\n"; } } class b extends a { } echo "** static: \n"; b::test_backtrace(); $b = new b(); echo "** object: \n"; $b->test_backtrace(); ?> Output Looks Like: ** static: class pre: a class bt: b class get_class: ** object: class pre: a class bt: b class get_class: b Perhaps get_class() could return the expected class name when called without arguements? -- Phil Dier gett communications <http://www.gettcomm.com/> gettlabs, inc. <http://www.gettlabs.com/>

« previous php.internals (#3309) next »