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 -

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to