It is a slightly annoying limitation.. - inherited static methods, cant guess their called class...
I did look at a fix a while ago - it involved adding a pointer to the called class name string, to the exectuter globals, whenever a function is called in the engine... - then to retrieve it became problematic as
- you cant really use a function as then it would assign the value again.
- no-one was too keen to have 'dynamic' constants...


Actually - I AFAIR someone said that it may be fixed in PHP5 back then :) - or suggested debug_backtrace.. (but I'm not sure if that is feasible)

Regards
Alan

Adam Bregenzer wrote:

Stig,

On Tue, 2004-02-03 at 17:27, Stig S. Bakken wrote:


Try __CLASS__.



Thank you for the reply. This does work for the class the method is
defined in, however unfortunately it's not a solution for classes that
inherit this method. Here's the sample code I used in my first post:




class Foo { function getClassName() {
// ???
}
}
class Bar extends Foo {
}


echo Foo::getClassName();  // returns 'foo'
echo Bar::getClassName();  // returns 'bar'

The solution I have right now that is inheritable, though very kludgy is
this:

class Foo { function someFunc($class_name) {
return $class_name;
}
} class Bar extends Foo {
function someFunc($class_name = NULL) {
return parent::someFunc(isset($class_name) ? $class_name : __CLASS__);
}
}




This does work, but I have to have this stub function copied into every
class that inherits Foo, plus I have an extra parameter in there.  Is
there no better way?

Thanks again,
Adam




-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to