3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Orig1 { public static function test() { echo "ok1\n"; } } class Orig2 { public static function test() { echo "ok2\n"; } } class Delegator { public static function delegate(object $orig) { static $cache = []; $origClass = get_class($orig); if (!isset($cache[$origClass])) { $className = 'Delegate__' . count($cache); $cache[$origClass] = $className; eval(" class $className { public static function __callStatic(\$name, \$args) { return $origClass::\$name(...\$args); } } "); } return new $cache[$origClass]($orig); } } $o1 = new Orig1(); $d1 = Delegator::delegate($o1); $o2 = new Orig2(); $d2 = Delegator::delegate($o2); $d1::test(); $d2::test(); $d1::test();
Output for git.master_jit, rfc.property-hooks, git.master
ok1 ok2 ok1

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:
41.08 ms | 1245 KiB | 4 Q