I have looked for other questions covering this error, but could not find a case that applies to my problem.
Basically the static method in my class invokes a non-static method which in return invokes another non-static method.
This throws an Fatal error:
Fatal error: Using $this when not in object context in class.php on line ...
I can't figure out why it is not okay to call a non-static class method from another non-static class method via $this. Is it because they are both invoked from a static function and hence there is no $this instance ?
Here is the (simplified) class:
class Redis_Provision {
public $redis = NULL;
public function redis_query()
{
if(is_null($this->redis)) {
$this->setBackend(); <------- This throws the fatal error
}
return $this->redis;
}
public function setBackend()
{
$this->redis = new Redis();
$this->redis->connect();
}
public static function activate()
{
if( self::redis_query()->ping())
{
// Do stuff
}
}
}
Which i would invoke via:
$redis_provision = new Redis_Provision();
$redis_provision->activate();