3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Animal{ private $name; public function __construct($name){ $this->name = $name; } public function say($say_func=null){ $say_func = is_callable($say_func)? $say_func: function(){ var_dump('default',$this); }; $say_func(); } } $b = function(){ var_dump('custom',$this); }; $a = new Animal('bob'); $a->say(); $a->say($b);
based on DIBhf
Output for 7.1.0 - 7.2.0
string(7) "default" object(Animal)#2 (1) { ["name":"Animal":private]=> string(3) "bob" } Fatal error: Uncaught Error: Using $this when not in object context in /in/hhv1t:20 Stack trace: #0 /in/hhv1t(15): {closure}() #1 /in/hhv1t(25): Animal->say(Object(Closure)) #2 {main} thrown in /in/hhv1t on line 20
Process exited with code 255.
Output for 5.4.9 - 7.0.20
string(7) "default" object(Animal)#2 (1) { ["name":"Animal":private]=> string(3) "bob" } Notice: Undefined variable: this in /in/hhv1t on line 20 string(6) "custom" NULL
Output for 5.3.19 - 5.3.29
Notice: Undefined variable: this in /in/hhv1t on line 13 string(7) "default" NULL Notice: Undefined variable: this in /in/hhv1t on line 20 string(6) "custom" NULL