Re: How to get class name in static function (PHP 4.2.3)

From: Date: Sun, 16 May 2004 18:16:26 +0000
Subject: Re: How to get class name in static function (PHP 4.2.3)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-186360@lists.php.net to get a copy of this message
* Thus wrote Torsten Roehr (roehr@zilleon.com): > Hi, > > does anyone know a way of how to get the name of the class within a static > function? I can't use __CLASS__ as my PHP version is 4.2.3 and I can't > upgrade. > > My code (simplified): > > class Base { > function Factory() { > $classname = ???; > return new $classname; > } > } > > class Event extends Base { > } > > // This should make $event an object of class Event > $event = Event::Factory(); > > Of course I could pass the classname as a parameter to the factory method > like: > $event = Event::Factory('Event'); > > But I would like to have a more generic solution. Any hints would be greatly > appreciated. Thanks in advance! The only Solution I can come up with: class Event extends Base { function Factory() { return parent::Factory('Event'); } } Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#186360) next »