3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class foo { private $bar = 5; public function showBar() { return $this->bar; } public function stupid(): callable { $_bar =& $this->bar; return function (int $v) use (&$_bar): void { $this->bar = $v; }; } } $foo = new foo; $bar = $foo->stupid()(36); echo $foo->showBar();
Output for 7.1.0 - 7.3.0beta1
36
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught TypeError: Return value of foo::{closure}() must be an instance of void, none returned in /in/n3njY:10 Stack trace: #0 /in/n3njY(14): foo->{closure}(36) #1 {main} thrown in /in/n3njY on line 10
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected '(' in /in/n3njY:14 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/n3njY on line 6
Process exited with code 255.