0

Consider below code, Iam using 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
    }
}

I have a doubt if get() is a static method then why it is not working with :: operator. As a reference What does this mean? "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM" In this question also the method is static but they did not justify why they used -> for static method. Any help is greatly appreciated.

Community
  • 1
  • 1
user3205479
  • 1,443
  • 1
  • 17
  • 41
  • 1
    http://stackoverflow.com/questions/3173501/whats-the-difference-between-double-colon-and-arrow-in-php – yogesh84 Mar 07 '17 at 07:12

1 Answers1

0
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 This saved me. Hope some one do not suffer again with this kind of php bug.

Community
  • 1
  • 1
user3205479
  • 1,443
  • 1
  • 17
  • 41