Re: Re: Get name of extending class with static method call (PHP5)
| From: | Andrey Hristov | Date: | Fri, 14 Jan 2005 07:29:14 +0000 |
| Subject: | Re: Re: Get name of extending class with static method call (PHP5) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14386@lists.php.net to get a copy of this message | ||
Christian Schneider wrote:
Torsten Roehr wrote: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__) {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,
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