How to fix the error Using $this when not in object context?

I have a class, take any when I want to access the variable $table that reacts strangely I have $this. What's the matter?

class CovertionPDF
{
 private $table = [];
 private $html;
 private $score;

 public static function getHTML($iOrder)
{
 $order = self::getPaysystem($iOrder);
 $this->table = 'Hello world';
}
}
June 3rd 19 at 18:54
2 answers
June 3rd 19 at 18:56
Solution
The error kicks due to the fact that you refer to the object context IN a STATIC METHOD.
But static methods are called WITHOUT CREATING an object (that's what static), then there is no object context no (TK not the object itself), and because there is no access to internals of the object (which, remember, is not).
June 3rd 19 at 18:58
class CovertionPDF
{
 static $table = [];
 private $html;
 private $score;

 public static function getHTML($iOrder)
{
 $order = self::getPaysystem($iOrder);
 self::$table = 'Hello world';
}
}
Why I can't refer to it as $this but only as static? - Vivienne_Skiles commented on June 3rd 19 at 19:01
Because a static method? - Vivienne_Skiles commented on June 3rd 19 at 19:04
Yes - jerod.Herm commented on June 3rd 19 at 19:07

Find more questions by tags PHP