3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class outerClass{ private $privateProp; protected $protectedProp; public function __construct($value){ $this->privateProp = $value; } public function innerClasses($innerClass){ switch($innerClass){ case 'accessPrivate': return new class($this->privateProp) extends outerClass{ }; } } } $test = new outerClass('testing'); $result = $test->innerClasses('accessPrivate'); var_dump($result);
based on UgcHk
Output for 7.0.0 - 7.2.0
object(class@anonymous)#2 (2) { ["privateProp":"outerClass":private]=> string(7) "testing" ["protectedProp":protected]=> NULL }
Output for 5.4.1 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/86QnM on line 21
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_CLASS in /in/86QnM on line 21
Process exited with code 255.