3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Ancestor { public $publicVar = "ancestor's public var\n"; static $staticVar = "ancestor's static var\n"; function publicMethod(){ echo "ancestor's publicMethod "; // is $this is set up if(isset($this)){ echo "is in object context\n"; }else{ echo "is in static context\n"; } } static function staticMethod(){ echo "ancestor's staticMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "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 "descendant's publicMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "in static context\n"; } } static function staticMethod(){ echo "descendant's staticMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "in static context\n"; } } } $ancestor = new Ancestor(); $descendant = new Descendant(); // From Outside Of An Instance/Class: // access to properties echo $descendant->publicVar; // descendant's public var //echo $descendant->staticVar; // "" + notice: Undefined property: Descendant::$staticVar echo $descendant::$staticVar; // descendant's static var //echo $descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Ancestor::$publicVar; // fatal error: Access to undeclared static property echo Ancestor::$staticVar; //ancestor's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property echo Descendant::$staticVar; // descendant's static var // access to methods $descendant->publicMethod(); $descendant->staticMethod(); $descendant::staticMethod(); $descendant::publicMethod(); //Ancestor::publicMethod();
Output for git.master, git.master_jit, rfc.property-hooks
descendant's public var descendant's static var ancestor's static var descendant's static var descendant's publicMethod in object context descendant's staticMethod in static context descendant's staticMethod in static context Fatal error: Uncaught Error: Non-static method Descendant::publicMethod() cannot be called statically in /in/B4XIT:70 Stack trace: #0 {main} thrown in /in/B4XIT on line 70
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.09 ms | 401 KiB | 8 Q