In the example below, I wanted to know why I can not use $this
inside a static class ?
<?php
class A{
public static function hello(){
echo 'hello';
}
}
class B extends A{
public function ok(){
echo 'ok';
}
public static function fprint(){
A::hello();
$this->ok();
}
}
$obj = new B;
$obj->fprint();
?>
The problem is in the fprint
method. I understand that a static method can be used without the need of an object, but if I call an object, as I did, the fprint
method does not need to use it to call the hello
method, since I use class A to this, and $this
will serve to call the ok
method with the instance object that I created. I do not understand why this gives error.
The error returned:
Fatal error: Using $ this when not in object context