"Andrey Hristov" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Christian Schneider wrote: > > Torsten Roehr wrote: > > > >> Something so straightforward and fundamental should be possible!?! > > > > > > Maybe is isn't as fundamental as you think? I never came across this > > problem in years of PHP programming. But then again I use classes with > > static calls for nothing but separate namespaces :-) > > > > I'm pretty sure there is another (possibly more elegant) solution. This > > is not a flame but a suggestion to rethink the problem you are trying to > > solve. > > > > - Chris > > > Hi Chris, > I have faced this limitation of the languagee when I was trying to simplify > code which uses Singleton and uses to have n-time the code for caching > copied around. Every new class that one subclass has to copy the code. A bit > overwork, isn't it? At the end we agreed on a solution with __CLASS__ in the > extending classes. > > class Foo { > function getInstanceInt($params, $class_name= __CLASS__) { > var_dump($params, $class_name); > /*...*/ > } > } > class Bar extends Foo { > function getInstance() { > Foo::getInstanceInt(func_get_args(), __CLASS__); > } > } > $a= Bar::getInstance(1,2,3); > > So the getInstance() in the subclasses is quite simple. One also > may declare argument names. Here I haven't done that for simplicity. > > Regards, > Andrey
Hi Andrey, thanks for your posts. It seems that this is the only viable solution - passing the class name in as a parameter. Thanks and best regards, Torsten Roehr -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php