Question d’entretien chez CarltonOne Engagement

class Test{ protected $var; public function __construct(){ $this->var=1; } public static someFunction(){ return $this->var *= 5; } } What is wrong with the code ?

Réponse à la question d'entretien

Utilisateur anonyme

5 nov. 2018

static function cannot use $this. We can use Class Name or self with scope resolution operation to reference a static variable. Test::$var or self::$var and also such referencing needs variable to be declared as static.