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
Output for git.master, git.master_jit, rfc.property-hooks
1 autoload A Success Demo 2 autoload B 3 autoload C Success Demo 4 autoload Y Fatal error: Uncaught TypeError: fail(): Argument #1 ($test) must be of type X, Demo given, called in /in/NuX6K on line 36 and defined in /in/NuX6K:32 Stack trace: #0 /in/NuX6K(36): fail(Object(Demo)) #1 {main} thrown in /in/NuX6K on line 32
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
84.77 ms | 401 KiB | 8 Q