3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait foo { static $bar = []; public function a() { static::$bar = ["foo"]; echo "Goodbye Moon"; } } class bing { use foo; public function a() { foo::a(); var_dump(self::$bar, foo::$bar); } public function b() { foo::a(); self::$bar[] = "bat"; var_dump(self::$bar, foo::$bar); } } $bing = new bing; $bing->a(); $bing->b();
based on UZ6gq
Output for 7.0.0 - 7.2.0
Deprecated: Non-static method foo::a() should not be called statically in /in/piUFm on line 16 Goodbye Moonarray(0) { } array(1) { [0]=> string(3) "foo" } Deprecated: Non-static method foo::a() should not be called statically in /in/piUFm on line 21 Goodbye Moonarray(1) { [0]=> string(3) "bat" } array(1) { [0]=> string(3) "foo" }
Output for 5.6.7 - 5.6.28
Deprecated: Non-static method foo::a() should not be called statically, assuming $this from incompatible context in /in/piUFm on line 16 Goodbye Moonarray(1) { [0]=> string(3) "foo" } array(0) { } Deprecated: Non-static method foo::a() should not be called statically, assuming $this from incompatible context in /in/piUFm on line 21 Goodbye Moonarray(2) { [0]=> string(3) "foo" [1]=> string(3) "bat" } array(0) { }
Output for 5.4.2 - 5.5.35
Strict Standards: Non-static method foo::a() should not be called statically, assuming $this from incompatible context in /in/piUFm on line 16 Goodbye Moonarray(1) { [0]=> string(3) "foo" } array(0) { } Strict Standards: Non-static method foo::a() should not be called statically, assuming $this from incompatible context in /in/piUFm on line 21 Goodbye Moonarray(2) { [0]=> string(3) "foo" [1]=> string(3) "bat" } array(0) { }
Output for 5.3.17 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/piUFm on line 2
Process exited with code 255.