3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $anon = function($arg1, $arg2 = 2) { var_dump($this->mine, $arg1, $arg2); }; class Me { protected $mine = 8; } $me = new Me; $args = [4, 2]; // This is ugly, and doesn't take a variable number of args $anon->call($me, $args[0], $args[1]); // This doesn't exist =( // $anon->apply($me, $args); // We took .bind() and .call() from JS, why not .apply()? // This is ugly too, but takes a variable number of args call_user_func_array(array($anon, 'call'), array_merge(array($me), $args));
Output for 7.0.0 - 7.2.0
int(8) int(4) int(2) int(8) int(4) int(2)
Output for 5.4.10 - 5.6.28
Fatal error: Call to undefined method Closure::call() in /in/MtJDj on line 15
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/MtJDj on line 12
Process exited with code 255.