Php 类构造静态未定义方法
我很困惑为什么会出现这样的错误:Php 类构造静态未定义方法,php,Php,我很困惑为什么会出现这样的错误: 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::$_ins
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;
}
}
我们扩展它
class ourmissionHelper extends smTitan {
public function getPostView() {
}
}
叫它:
ourmissionHelper::this(array("post_type"=>"about"))->getPostView();
我得到了这个错误:
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;
}
}
致命错误:调用未定义的方法smTitan::getPostView()
这对我来说并不重要,因为getPostView是我们的MissionHelper的一部分,它扩展了smTitan,所以它应该能够访问它,但它将this()构造中的第一个类作为唯一的实例处理。。。除了通过复制类来实现这一点之外,还有其他想法吗?
self
总是指编写它的类,而不是任何扩展类。您希望在类中添加一个属性,这只有在PHP5.3中使用static
关键字后才可能实现。因此,new static()
而不是new self()
self
总是指编写它的类,而不是任何扩展类。您希望在类中添加一个属性,这只有在PHP5.3中使用static
关键字后才可能实现。因此,new static()
而不是new self()
self
总是指编写它的类,而不是任何扩展类。您希望在类中添加一个属性,这只有在PHP5.3中使用static
关键字后才可能实现。因此,new static()
而不是new self()
self
总是指编写它的类,而不是任何扩展类。您希望在类中添加一个属性,这只有在PHP5.3中使用static
关键字后才可能实现。因此,newstatic()
而不是newself()