PHP static objects giving a fatal error?

Well, I think your Customer::getInstance() method is flawed. It should look like this: static function getInstance() { if(self::$class == false) { self::$class = new Customer; return self::$class; // ADDED! } else { return self::$class; } } In the if(self::$class == false) branch you are creating the instance of the class, but you don't return it You could also rewrite it as such: static function getInstance() { if(self::$class == false) { self::$class = new Customer; } return self::$class; } To make it a bit shorter.

Well, I think your Customer::getInstance() method is flawed. It should look like this: ... static function getInstance() { if(self::$class == false) { self::$class = new Customer; return self::$class; // ADDED! } else { return self::$class; } } .... In the if(self::$class == false) branch you are creating the instance of the class, but you don't return it.

You could also rewrite it as such: static function getInstance() { if(self::$class == false) { self::$class = new Customer; } return self::$class; } To make it a bit shorter.

1 Your edit improved your answer. – John Conde May 5 '10 at 13:50 Cheers Max, you saved me a headache. It's amazing what you miss when you're tired.

– Webbo May 5 '10 at 13:53.

DRY: Don't Repeat Yourself static function getInstance() { if(self::$class == false) { self::$class = new Customer; } return self::$class; } And for Sinlgetons it is also important to prevent __clone() from being used. Making it private should solve that problem: private function __clone() {}.

Fatal error: Call to a member function set() on a non-object in /.../classes/customer. Can anyone tell me why I get this error? I know this code might look strange, but it's based on a component system that I'm writing for a CMS.

The aim is to be able to replace HTML tags in the template e.g. If anyone can think of a better way, please let me know but in the first instance, I'd like to know why I get the "Fatal error" mentioned above.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions