3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Value { protected $value; public function __construct($value) { $this->value = $value; } public function getValue() { return $this->value; } } $three = new Value(3); $four = new Value(4); $closure = function ($delta) { var_dump($this->getValue() + $delta); }; $closure(4); $closure->call($three, 4); $closure->call($four, 4); ?>
based on StD6l
Output for 7.0.0 - 7.2.12
Fatal error: Uncaught Error: Using $this when not in object context in /in/4uLij:17 Stack trace: #0 /in/4uLij(18): {closure}(4) #1 {main} thrown in /in/4uLij on line 17
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: $this is null in /in/4uLij:-1 Stack trace: #0 /in/4uLij(-1): Closure$() #1 {main}
Process exited with code 255.
Output for hhvm-3.17.3 - 3.21.3
Fatal error: Uncaught Error: $this is null in /in/4uLij:17 Stack trace: #0 /in/4uLij(18): Closure$() #1 {main}
Process exited with code 255.
Output for hhvm-3.11.1 - 3.15.4
Fatal error: Uncaught Error: $this is null in /in/4uLij:17 Stack trace: #0 /in/4uLij(18): Closure$getValue() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.1
Fatal error: $this is null in /in/4uLij on line 17
Process exited with code 255.
Output for 5.3.22 - 5.6.38
Fatal error: Using $this when not in object context in /in/4uLij on line 17
Process exited with code 255.