PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] Using $this when not in object context on yii

 January 09, 2022     php, yii     No comments   

Issue

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?


Solution

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.



Answered By - Pavel Lint
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing