PHP Fatal error: Uncaught Error: Using $this when not in object context in file.php

Reading Time: < 1 minutes
class Foo {
	protected $_value;

	public function __construct(){

		return $this->_value = 1;

	public static function getValue(){

		return $this->_value * 5;

echo Foo::getValue();

As per php documentation,

Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside methods declared as static.

In the above code snippet, static method getValue() will throw the error this is the same use case.

Things to be noted in Static Method and Static Variable:

Static properties are accessed using the Scope Resolution Operator (::) and cannot be accessed through the object operator (-&gt;).

It’s possible to reference the class using a variable. The variable’s value cannot be a keyword (e.g. selfparent and static).