3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Demo { } // An "autoload" handler creating an alias for the same class spl_autoload_register(function ($class) { echo "autoload $class\n"; class_alias('Demo', $class); }); // Create a Demo object using "A" // and pass that to function expecting "A" function success(A $test) { echo "Success ".get_class($test)."\n"; } echo "1\n"; success(new A()); // Create a Demo object using "B", // then create another Demo object using "C" // and pass that to function expecting "B" function also(B $test) { echo "Success ".get_class($test)."\n"; } echo "2\n"; new B(); echo "3\n"; also(new C()); // Create a Demo object using "X", // and pass that to function expecting "B" function fail(X $test) { echo "Success ".get_class($test)."\n"; } echo "4\n"; fail(new Y()); // Note that all of these names refer to the same class, // and all objects are of the same class

preferences:
45.78 ms | 402 KiB | 5 Q