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

From: Date: Tue, 18 May 2004 09:41:43 +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-186463@lists.php.net to get a copy of this message
roehr@zilleon.com wrote:
Burhan Khalid <phplist@meidomus.com> schrieb am 18.05.2004, 10:48:29:
Torsten Roehr wrote:
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();
Have you tried get_class($this) ?
Hi Burhan, the problem is that in a static class/method there is no $this. Any other ideas?
Yeah, I just realized that as I hit send. I have another idea though. Get all the classes with get_declared_classes(), then loop through the resulting array with is_callable() and see which class has the function that you are in?

« previous php.general (#186463) next »