3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class myName{ private $prop; public function __construct($value){ $this->prop = $value; } public function returnPrivate(){ return $this->prop; } } $oldObject = new myName('The named way'); echo $oldObject->returnPrivate()."\n"; $newObj = new class('The anonymous way') extends myName{ public function returnPrivate(){ return $this->$propName.' with override'; } }; echo $newObj->returnPrivate();
based on FetsX
Output for 7.1.0 - 7.2.0
The named way Notice: Undefined variable: propName in /in/NMVNd on line 29 Notice: Undefined property: class@anonymous::$ in /in/NMVNd on line 29 with override
Output for 7.0.0 - 7.0.20
The named way Notice: Undefined variable: propName in /in/NMVNd on line 29 Fatal error: Uncaught Error: Cannot access empty property in /in/NMVNd:29 Stack trace: #0 /in/NMVNd(35): class@anonymous->returnPrivate() #1 {main} thrown in /in/NMVNd on line 29
Process exited with code 255.
Output for 5.4.1 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/NMVNd on line 25
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_CLASS in /in/NMVNd on line 25
Process exited with code 255.