3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $class_aliases = [ 'FooAlias' => 'Foo' ]; spl_autoload_register(function($class) { if (isset($class_aliases[$class])) { class_alias($class_aliases[$class], $class); var_dump($class); return true; } }); class Foo {} class Bar extends Foo {} class FooCreator { public function create(FooAlias $foo) { } } $foo = new Bar; $creator = new FooCreator(); $alias = new FooAlias; var_dump($alias); $creator->create($foo);
based on oM65J
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Class 'FooAlias' not found in /in/Z8NWf:30 Stack trace: #0 {main} thrown in /in/Z8NWf on line 30
Process exited with code 255.
Output for 5.4.9 - 5.6.28
Fatal error: Class 'FooAlias' not found in /in/Z8NWf on line 30
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Z8NWf on line 3
Process exited with code 255.