3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Calling static trait method foo::a is deprecated, it should only be called on a class using the trait in /in/piUFm on line 16 Fatal error: Uncaught Error: Non-static method foo::a() cannot be called statically in /in/piUFm:16 Stack trace: #0 /in/piUFm(28): bing->a() #1 {main} thrown in /in/piUFm on line 16
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught Error: Non-static method foo::a() cannot be called statically in /in/piUFm:16 Stack trace: #0 /in/piUFm(28): bing->a() #1 {main} thrown in /in/piUFm on line 16
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
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 7.3.32 - 7.3.33
Goodbye Moonarray(0) { } array(1) { [0]=> string(3) "foo" } 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.4.45, 5.5.24 - 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) { }

preferences:
154.61 ms | 403 KiB | 226 Q