Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal error: Using $this when not in object context
    primarykey
    data
    text
    <p>I have this class which I wrote for a factory method and I keep getting an error on line 22 which states:</p> <p><em>Fatal error: Using $this when not in object context</em> </p> <p>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.</p> <p>my class is called as such:</p> <pre><code>$class = AisisCore_Factory_Pattern('class_you_want'); </code></pre> <p>And then from there the following is executed:</p> <pre><code>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-&gt;_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'; } } </code></pre> <p>where it freaks out is on:</p> <pre><code>$this-&gt;_create_dependecies(); </code></pre> <p>I'm not sure how that's out of context or how I would properly call it....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload