3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $alias_list = []; $alias_autoloader = function($class_name) use (&$alias_list) { if (isset($alias_list[strtolower($class_name)])) { class_alias($alias_list[strtolower($class_name)], $class_name); return true; } }; $alias = function($from, $to) use (&$alias_list) { $alias_list[strtolower($to)] = $from; }; spl_autoload_register($alias_autoloader); class Foo { function test() { return get_class($this); } } $alias('Foo', 'Bar'); function hint_on_bar(Bar $bar) { return "worked"; } class_exists(Bar); $b = new Foo; var_dump(hint_on_bar($b));
based on 7nn9U
Output for 7.2.0
Warning: Use of undefined constant Bar - assumed 'Bar' (this will throw an Error in a future version of PHP) in /in/98gAJ on line 36 string(6) "worked"
Output for 5.4.10 - 7.1.10
Notice: Use of undefined constant Bar - assumed 'Bar' in /in/98gAJ on line 36 string(6) "worked"
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/98gAJ on line 3
Process exited with code 255.