3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Declarations and code in the global namespace namespace { class A { public function __construct($x) { echo(get_called_class().'::__construct('.$x.")\n"); } public static function someMethod($y) { echo(get_called_class().'::someMethod('.$y.")\n"); } } // No namespace, no problem $className = 'A'; $o = new $className(3); $className::someMethod('abc'); } // Use another namespace namespace N { class B extends \A {} } // Another namespace again namespace M { use N\B as B; // Use full class name $newName = 'N\B'; $o = new $newName('namespaced'); $newName::someMethod('works'); // Using a class alias works when used in code $o = new B('this works'); // This doesn't work, the class name must be full $newName = 'B'; $o = new $newName("this doesn't work"); }
Output for rfc.property-hooks, git.master, git.master_jit
A::__construct(3) A::someMethod(abc) N\B::__construct(namespaced) N\B::someMethod(works) N\B::__construct(this works) Fatal error: Uncaught Error: Class "B" not found in /in/lg2qC:30 Stack trace: #0 {main} thrown in /in/lg2qC on line 30
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:
129.86 ms | 2237 KiB | 4 Q