3v4l.org

run code in 300+ PHP versions simultaneously
<?php $closures = array(); $simple_closure = function($msg="hello world") { return $msg;}; for ($x=0; $x < 2; $x++) { $closures[$x] = $simple_closure; } $obj1 = new stdClass; $obj1->msg = "top of the morning"; $obj2 = new stdClass; $obj2->msg = "joy to the world"; $c1 = Closure::bind($closures[0], $obj1); $c2 = Closure::bind($closures[1], $obj2); var_dump($c1,$c2); echo $c1($this->msg); echo $c2($this->msg);

preferences:
36.64 ms | 402 KiB | 5 Q