Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So if you are trying to do this as a singleton your get_instance() method needs to be defined statically. further how are you calling create()? I see no reference to that at all. Perhaps create() should be a public static function and then change your $this->_create_dependecies(); to self::_create_dependencies() and add the static keyword to your definition of the create_dependencies method so it would be public static function create_dependencies. Then you put it all together with...</p> <pre><code>$class = AisisCore_Factory_Pattern::create('class_you_want'); class AisisCore_Factory_Pattern { protected static $_class_instance; protected static $_dependencies; public static function get_instance(){ if(self::$_class_instance == null){ $_class_instance = new self(); } return self::$_class_instance; } public static function create($class){ if(empty($class)){ throw new AisisCore_Exceptions_Exception('Class cannot be empty.'); } if(null === self::$_dependencies){ self::_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 static function _create_dependecies(){ self::$_dependencies = get_template_directory() . '/functions.php'; } </code></pre> <p>}</p> <p>and that should do ya. if you really want to access it non statically (yes I know that's not a real word but I like it) you should be saying something like this...</p> <pre><code>$class = AisisCore_Factory_Pattern::get_instance()-&gt;create('class_you_want'); //or... $class = AisisCore_Factory_Pattern::get_instance(); $newclass = $class-&gt;create('class_you_want'); </code></pre> <p>of course in the second example you would remove the static keyword from the create function definition</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