84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
I have this method and I want to use $this in it, but all I get is: Fatal error: $this is not used in an object context.
How can I make it work?
public static function userNameAvailibility() { $result = $this->getsomthin(); }
You cannot use$thisinside a static function because static functions are independent of any instantiated object. Try to make the function not static.
$this
edit: By definition, static methods can be called without any instantiated object, so using$thisin a static method doesn't make any sense.
This is the right thing to do
public static function userNameAvailibility() { $result = self::getsomthin(); }
Forstatic methods, useself::instead of$this->.
self::
$this->
See:PHP Static Method TutorialMore information:)
You cannot use
$this
inside a static function because static functions are independent of any instantiated object. Try to make the function not static.edit: By definition, static methods can be called without any instantiated object, so using
$this
in a static method doesn't make any sense.This is the right thing to do
Forstatic methods, use
self::
instead of$this->
.See:PHP Static Method TutorialMore information:)