I have seen registry pattern questions on here, but right now I'm being thrown off by the error message I'm receiving: Using $this when not in object context
...
I took the code sample from http://avedo.net/101/the-registry-pattern-and-php/ and I have pored over these lines of code, but I just can't wrap my head around the problem.
EDIT: I get the feeling from the answers that the article I've linked to shouldn't be considered "working code"...
Here is a snippet of my registry class code:
class registry {
//Holds variables, objects, etc.
private $reg = array();
private static $instance = null;
public static function getInstance() {
if($this->instance === null) { //THROWS THE FATAL ERROR
$this->instance = new registry();
}
return $this->instance;
}
//Disallow creation of new objects, forcing use of the Singleton
private function __construct() {}
private function __clone() {}
What I'm not really understanding is WHY this is throwing that error. The way I understood $this
was that it referred to whatever called the method, which is this snippet from my init.php file:
//Instantiate registry
$registry = registry::getInstance();
I'm feeling a little burned out from reading and coding (these past few days I've been dedicated to teaching myself how MVC works by building my own barebones little web framework). I must be missing something simple, but it also seems to me that this is exactly what the article illustrates. For what it's worth, I'm using PHP 5.x.
If anyone feels they need to clear up some of these concepts for me, please feel free. :) As always, thanks for taking the time to read this.