3v4l.org

run code in 300+ PHP versions simultaneously
<?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.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
int(8) int(4) int(2) int(8) int(4) int(2)
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Call to undefined method Closure::call() in /in/MtJDj on line 15
Process exited with code 255.

preferences:
240.58 ms | 402 KiB | 327 Q