3v4l.org

run code in 300+ PHP versions simultaneously
<?php class sM { static private $_methods = array(); static public function addMethod($name, Closure $cb) { self::$_methods[$name] = $cb; } public function __call($name, array $args) { array_unshift($args, $this); return call_user_func_array(self::$_methods[$name], $args); } public function add($a, $b) { return $a + $b; } } sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); $sM = new sM(); echo $sM->add10(1)."\n"; echo $sM->add100(1)."\n"; foreach(array(100) as $base) { sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); } echo $sM->add100(1)."\n"; echo $sM->add1000(1)."\n";
Output for git.master_jit, git.master, rfc.property-hooks
Warning: Undefined variable $base in /in/5V1EJ on line 25 Warning: Undefined variable $base in /in/5V1EJ on line 25 Warning: Undefined array key "add10" in /in/5V1EJ on line 15 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/5V1EJ:15 Stack trace: #0 /in/5V1EJ(31): sM->__call('add10', Array) #1 {main} thrown in /in/5V1EJ on line 15
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:
63.23 ms | 401 KiB | 8 Q