3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public function save($a = 1, $b = 2) { printf('Class name %s, A = %s, B = %s%s', get_class($this), $a, $b, PHP_EOL); } } class B extends A { public function test() { $closure = Closure::fromCallable('parent::save'); $closure->bindTo($this); $invoker = new Invoker(); $invoker->run($closure, func_get_args()); } } class Invoker { public function run(Closure $closure, array $params) { $closure(...$params); } } $o = new B; $o->test(); $o->test('fff'); $o->test(100, 500); $o->test('a', 'b', 'c');
Output for 7.1.0 - 7.3.0rc3
Class name B, A = 1, B = 2 Class name B, A = fff, B = 2 Class name B, A = 100, B = 500 Class name B, A = a, B = b
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/TBRl6:15 Stack trace: #0 /in/TBRl6(31): B->test() #1 {main} thrown in /in/TBRl6 on line 15
Process exited with code 255.
Output for hhvm-3.18.4 - 3.21.0
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/TBRl6:15 Stack trace: #0 /in/TBRl6(31): B->test() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Call to undefined method Closure::fromCallable() in /in/TBRl6 on line 15
Process exited with code 255.