3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; } } foreach(array(10) as $base) { 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";
based on fFagD
Output for 5.6.30, 7.0.30 - 7.3.0alpha1
11 Notice: Undefined index: add100 in /in/Sc224 on line 15 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/Sc224 on line 15 101 Notice: Undefined index: add1000 in /in/Sc224 on line 15 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/Sc224 on line 15
Output for hhvm-3.22.0
11 Notice: Undefined index: add100 in /in/Sc224 on line -1 Warning: Invalid argument: function: not string, closure, or array in /in/Sc224 on line -1 101 Notice: Undefined index: add1000 in /in/Sc224 on line -1 Warning: Invalid argument: function: not string, closure, or array in /in/Sc224 on line -1
Output for hhvm-3.18.5 - 3.21.3
11 Notice: Undefined index: add100 in /in/Sc224 on line 15 Warning: Invalid argument: function: not string, closure, or array in /in/Sc224 on line 15 101 Notice: Undefined index: add1000 in /in/Sc224 on line 15 Warning: Invalid argument: function: not string, closure, or array in /in/Sc224 on line 15