3v4l.org

run code in 300+ PHP versions simultaneously
<?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.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
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 5.0.3 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
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.3.11, 4.4.0 - 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

preferences:
215.2 ms | 401 KiB | 325 Q