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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux