0

short question to a little php problem.

class topclass {
protected $test;
//....
}

class childclass extends topclass {`
public static function accessVariable(){

//HOW CAN I ACCESS THE $Test VARIABLE OF THE SUPERCLASS HERE?

}...

Can somebody help me?

Thx very much in advance

J-H
  • 1,795
  • 6
  • 22
  • 41

1 Answers1

5

Use self::$test or parent::$test for static function and $this->test for regular function. Protected variables are available within the scope of the extending classes, private variable are not.

The difference between using self::$test and parent::$test is that if you have overridden $test in the child class you would get the overridden value when using self::$test.

Of course if you wish to access the property statically, you need to declare it as static (i.e. protected static $test).

Mike Brant
  • 70,514
  • 10
  • 99
  • 103