【问题标题】::: does not work for static methods when model class is loaded - Codeigniter:: 在加载模型类时不适用于静态方法 - Codeigniter
【发布时间】:2017-07-27 07:15:09
【问题描述】:

考虑下面的代码,我正在使用 codeigniter 3.0

Xmodel.php
---------------------
class Xmodel {
    public static function get(){

    }
}

Ymodel.php
------------------------
class Ymodel(){
    public function run(){
         $this->load->model('XModel', 'x');
         $this->x::get(); // syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
         $this->x->get(); // works as expected
    }
}

我怀疑get() 是否是静态方法,那么为什么它不能与:: 运算符一起使用。作为参考What does this mean? "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM" 在这个问题中,该方法也是静态的,但他们没有证明为什么他们使用-> 作为静态方法。非常感谢任何帮助。

【问题讨论】:

标签: php codeigniter


【解决方案1】:
class Ymodel(){
     public function run(){
         $this->load->model('XModel', 'x');
         $a = $this->x; // save to a var
         $a::get(); // works as expected
     }
}

https://stackoverflow.com/a/11520244/3205479这救了我。希望有人不要再遭受这种 php 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 2021-03-09
    • 2020-02-15
    • 2017-10-05
    • 1970-01-01
    • 2012-07-02
    • 2017-07-15
    相关资源
    最近更新 更多