Hello,

As the %subj% says.. can't get it to work with PHP5. I mean, you could
do this kind of stuff with templates/generics on other languages and
then make a class singleton by just inheriting from base Singleton
class. No need to redefine GetInstance() (which usually contains the
same redundant kind of code). It should look something like this in
PHP5:

class Test extends Singleton
{
  // no singleton-specific code here
}

abstract class Singleton
{
  private static $instance = null;
  private function __construct() {}
  private function __clone() {}
  public static function GetInstance()
  {
    if (!isset(self::$instance))
      self::$instance = new self; // <-- doesnt really work

    return self::$instance;
  }
}

The problem is that self refers to Singleton class. I have also been
playing with __CLASS__ magic constant but it does the same thing.
Someone got it working the right way?

Reply via email to