3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait A { function calc1($v) { echo '/ calc1 trait /'; } function calc($v) { echo '/ calc trait /'.$x; } } class MyClass { use A; public $x; function calc($v) { echo '/ calc class /'; A::calc(5); //parent::calc($v); } } $x=new MyClass(); $x->x = 5; $x->calc(123);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
/ calc class / Deprecated: Calling static trait method A::calc is deprecated, it should only be called on a class using the trait in /in/nYe0H on line 17 Fatal error: Uncaught Error: Non-static method A::calc() cannot be called statically in /in/nYe0H:17 Stack trace: #0 /in/nYe0H(24): MyClass->calc(123) #1 {main} thrown in /in/nYe0H on line 17
Process exited with code 255.
Output for 8.0.0 - 8.0.30
/ calc class / Fatal error: Uncaught Error: Non-static method A::calc() cannot be called statically in /in/nYe0H:17 Stack trace: #0 /in/nYe0H(24): MyClass->calc(123) #1 {main} thrown in /in/nYe0H 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
/ calc class / Deprecated: Non-static method A::calc() should not be called statically in /in/nYe0H on line 17 Notice: Undefined variable: x in /in/nYe0H on line 7 / calc trait /
Output for 7.3.32 - 7.3.33
/ calc class // calc trait /
Output for 5.6.8 - 5.6.28
/ calc class / Deprecated: Non-static method A::calc() should not be called statically, assuming $this from incompatible context in /in/nYe0H on line 17 Notice: Undefined variable: x in /in/nYe0H on line 7 / calc trait /
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35
/ calc class / Strict Standards: Non-static method A::calc() should not be called statically, assuming $this from incompatible context in /in/nYe0H on line 17 Notice: Undefined variable: x in /in/nYe0H on line 7 / calc trait /

preferences:
196.89 ms | 402 KiB | 228 Q