3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function getFunc($text) { return function() use ($text) { $withNewLine = $text.PHP_EOL; printf("From the inside: %s", $withNewLine); return $withNewLine; }; } } $b = new A(); $func = $b->getFunc('can i has var'); $func(); $c = $b->getFunc('can i has var')(); echo 'From the outside:'.PHP_EOL; echo $c; var_dump($func = $b->getfunc("can i has var")());

preferences:
36.58 ms | 402 KiB | 5 Q