[PHP5] How to knwo object class name in a function called statically ?

From: Date: Thu, 07 Oct 2004 07:36:40 +0000
Subject: [PHP5] How to knwo object class name in a function called statically ?
Groups: php.general 
Request: Send a blank email to php-general+get-198803@lists.php.net to get a copy of this message
Hello - I have this code : abstract class foo { private __construct() {} public static getInstance() {
      static $instance = null;
      if (is_null($instance) == false)
         return $instance;
      else
      {
         $class = __CLASS__;
         return new $class();
      }
} } class extendedFoo extends foo { ... } $instance = extendedFoo::getInstance(); echo (get_class($instance)); My problem is that get_class($instance) return "foo" instead of "extendedFoo" !!! How to knwo the calling object type in a function called statically ? Reflection ? Other solution ??? Bug ???? I can resolve my probleme with a extendedFoo::getInstance() function, and adding a parameter $class to foo::getInstance(), but i don't want duplicated code in all foo subclass... Fred -

« previous php.general (#198803) next »