3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Ancestor { public $publicVar = "ancestor's public var\n"; static $staticVar = "ancestor's static var\n"; function publicMethod(){ echo "this is ancestor's public method\n"; // is $this is set up if(isset($this)){ echo "publicMethod is in object context\n"; }else{ echo "publicMethod is in static context\n"; } } static function staticMethod(){ echo "this is ancestor's static method\n"; // is $this is set up if(isset($this)){ echo "staticMethod is in object context\n"; }else{ echo "staticMethod is in static context\n"; } } } class Descendant extends Ancestor { public $publicVar = "descendant's public var\n"; static $staticVar = "descendant's static var\n"; function publicMethod(){ echo "this is descendant's public method\n"; // is $this is set up if(isset($this)){ echo "publicMethod is in object context\n"; }else{ echo "publicMethod is in static context\n"; } } static function staticMethod(){ echo "this is descendant's static method\n"; // is $this is set up if(isset($this)){ echo "staticMethod is in object context\n"; }else{ echo "staticMethod is in static context\n"; } } } $ancestor = new Ancestor(); $descendant = new Descendant(); // From Outside Of An Instance/Class: echo Ancestor::$publicVar; echo Ancestor::$staticVar; echo Descendant::$publicVar; echo Descendant::$staticVar; //Ancestor::publicMethod();
based on 3mYJD
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Access to undeclared static property: Ancestor::$publicVar in /in/O9fpa:55 Stack trace: #0 {main} thrown in /in/O9fpa on line 55
Process exited with code 255.
Output for 5.3.18 - 5.6.28
Fatal error: Access to undeclared static property: Ancestor::$publicVar in /in/O9fpa on line 55
Process exited with code 255.