I have this class which I wrote for a factory method and I keep getting an error on line 22 which states:
Fatal error: Using $this when not in object context
I have seen other peoples posts and similar questions but alas I don't understand whats going on enough to be able to apply what they took as an answer to my situation.
my class is called as such:
$class = AisisCore_Factory_Pattern('class_you_want');
And then from there the following is executed:
class AisisCore_Factory_Pattern {
protected static $_class_instance;
protected static $_dependencies;
public function get_instance(){
if(self::$_class_instance == null){
$_class_instance = new self();
}
return self::$_class_instance;
}
public function create($class){
if(empty($class)){
throw new AisisCore_Exceptions_Exception('Class cannot be empty.');
}
if(null === self::$_dependencies){
$this->_create_dependecies();
}
if(!isset(self::$_dependencies['dependencies'][$class])){
throw new AisisCore_Exceptions_Exception('This class does not exist in the function.php dependecies array!');
}
if(isset(self::$_dependencies['dependencies'][$class]['arguments'])){
$new_class = new $class(implode(', ', self::$_dependencies['dependencies'][$class]['params']));
return $new_class;
}else{
$new_class = new $class();
return $new_class;
}
}
private function _create_dependecies(){
self::$_dependencies = get_template_directory() . '/functions.php';
}
}
where it freaks out is on:
$this->_create_dependecies();
I'm not sure how that's out of context or how I would properly call it....
static, and useself::_create_dependencies()create()on the class?