3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Herp { function foo() { $this->bar(); } function bar() { var_dump('in trait'); } } class Derp { use Herp; function bar() { var_dump('in class'); Herp::bar(); } } (new Derp())->foo();
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(8) "in class" Deprecated: Calling static trait method Herp::bar is deprecated, it should only be called on a class using the trait in /in/ODZCF on line 17 Fatal error: Uncaught Error: Non-static method Herp::bar() cannot be called statically in /in/ODZCF:17 Stack trace: #0 /in/ODZCF(5): Derp->bar() #1 /in/ODZCF(20): Derp->foo() #2 {main} thrown in /in/ODZCF on line 17
Process exited with code 255.
Output for 8.0.0 - 8.0.30
string(8) "in class" Fatal error: Uncaught Error: Non-static method Herp::bar() cannot be called statically in /in/ODZCF:17 Stack trace: #0 /in/ODZCF(5): Derp->bar() #1 /in/ODZCF(20): Derp->foo() #2 {main} thrown in /in/ODZCF on line 17
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
string(8) "in class" Deprecated: Non-static method Herp::bar() should not be called statically in /in/ODZCF on line 17 string(8) "in trait"
Output for 7.3.32 - 7.3.33
string(8) "in class" string(8) "in trait"
Output for 5.6.7 - 5.6.28
string(8) "in class" Deprecated: Non-static method Herp::bar() should not be called statically, assuming $this from incompatible context in /in/ODZCF on line 17 string(8) "in trait"
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35
string(8) "in class" Strict Standards: Non-static method Herp::bar() should not be called statically, assuming $this from incompatible context in /in/ODZCF on line 17 string(8) "in trait"

preferences:
218.22 ms | 402 KiB | 227 Q