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 $this->privateProp; return new class($this->value) extends outerClass{ }; } } } $test = new outerClass('testing'); $result = $test->innerClasses('accessPrivate'); var_dump($result);
based on BJEcG
Output for 7.0.0 - 7.2.0
Notice: Undefined property: outerClass::$value in /in/UgcHk on line 23 object(class@anonymous)#2 (2) { ["privateProp":"outerClass":private]=> NULL ["protectedProp":protected]=> NULL }
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/UgcHk on line 23
Process exited with code 255.