3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function buildDynamicClass($parent, $child) { $reflection = new ReflectionClass($child); if($reflection->isAbstract()) { $abstract = 'abstract'; } else { $abstract = ''; } eval($abstract.' class '.$parent.' extends '.$child.' { }'); } function buildDynamicClass2($parent, $child) { class_alias($child, $parent); } class A { } $start = microtime(TRUE); for($i=0;$i<10000;$i++) { buildDynamicClass('A', 'B'.$i); } echo 'buildDynamicClass: '.(microtime(TRUE)-$start); $start = microtime(TRUE); for($i=0;$i<10000;$i++) { buildDynamicClass2('A', 'B'.$i); } echo 'buildDynamicClass2: '.(microtime(TRUE)-$start);
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught ReflectionException: Class B0 does not exist in /in/e142L:5 Stack trace: #0 /in/e142L(5): ReflectionClass->__construct('B0') #1 /in/e142L(27): buildDynamicClass('A', 'B0') #2 {main} thrown in /in/e142L on line 5
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: Uncaught exception 'ReflectionException' with message 'Class B0 does not exist' in /in/e142L:5 Stack trace: #0 /in/e142L(5): ReflectionClass->__construct() #1 /in/e142L(27): buildDynamicClass() #2 {main}
Process exited with code 255.
Output for 5.0.3 - 5.6.28
Fatal error: Uncaught exception 'ReflectionException' with message 'Class B0 does not exist' in /in/e142L:5 Stack trace: #0 /in/e142L(5): ReflectionClass->__construct('B0') #1 /in/e142L(27): buildDynamicClass('A', 'B0') #2 {main} thrown in /in/e142L on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Fatal error: Uncaught exception 'ReflectionException' with message 'Class B0 does not exist' in /in/e142L:5 Stack trace: #0 /in/e142L(27): buildDynamicClass('B0') #1 {main} thrown in /in/e142L on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/e142L on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/e142L on line 5