Reputation: 1075
I am baffled why I get this error:
class smTitan {
private static $_instance = null;
public static function this($att){
if (!self::$_instance) self::$_instance = new self();
if ($att !== NULL) {
self::$_instance->_att = $att;
self::$_instance->_results = new WP_Query( $att );
}
return self::$_instance;
}
}
We extend it
class ourmissionHelper extends smTitan {
public function getPostView() {
}
}
Call it:
ourmissionHelper::this(array("post_type"=>"about"))->getPostView();
and I get this error:
Fatal error: Call to undefined method smTitan::getPostView()
That makes no since to me, getPostView is part of ourmissionHelper which extends smTitan, so it should be able to access it, but its treating the first class from the this() construct as the only instance... Any ideas, other than copying over the class to get this to work?
Upvotes: 0
Views: 46
Reputation: 522165
self
always refers to the class that it is written in, never any extending classes. You want a late-binding static reference to your class, which is only possible since PHP 5.3 using the static
keyword. So, new static()
instead of new self()
.
Upvotes: 3