3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { function foo( callable $func ) { $func(); } function bar() { return 'bar'; } } (new A)->foo( function() { echo 'foo' . $this->bar(); } );
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/W6P2R:17 Stack trace: #0 /in/W6P2R(7): {closure}() #1 /in/W6P2R(18): A->foo(Object(Closure)) #2 {main} thrown in /in/W6P2R on line 17
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Fatal error: Using $this when not in object context in /in/W6P2R on line 17
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/W6P2R on line 16
Process exited with code 255.