1
class ModelFile extends CoreModel{

public $var;
public $var2;

public static function getId() {
   $this->var = '123';
}
}

I have above model. I am facing issue while using assigned variable. The error I get on above code is

Fatal error: Using $this when not in object context

Any idea of this issue?

1
  • 1
    Remove static from getId function. Commented May 31, 2018 at 9:08

1 Answer 1

1

You cannot access $this in static methods because they don't belong to any instance, but to the whole class instead. In your case, just remove static keyword.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.