3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types = 1); class Foo { public function __construct() { $closure = static function () : void { $this->bar(); }; $closure(); } public function bar() : void {} } new Foo();
based on nr5Bl
Output for 7.0.30 - 7.3.1
Fatal error: Uncaught Error: Using $this when not in object context in /in/58jnj:8 Stack trace: #0 /in/58jnj(10): Foo::{closure}() #1 /in/58jnj(16): Foo->__construct() #2 {main} thrown in /in/58jnj on line 8
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: $this is null in /in/58jnj:-1 Stack trace: #0 /in/58jnj(-1): Closure$Foo::__construct() #1 /in/58jnj(-1): Foo->__construct() #2 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: $this is null in /in/58jnj:8 Stack trace: #0 /in/58jnj(10): Closure$Foo::__construct() #1 /in/58jnj(16): Foo->__construct() #2 {main}
Process exited with code 255.
Output for 5.6.30
Warning: Unsupported declare 'strict_types' in /in/58jnj on line 1 Parse error: syntax error, unexpected ':', expecting '{' in /in/58jnj on line 7
Process exited with code 255.