3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait A { function calc1($v) { echo '/ calc1 trait /'; } function calc($v) { echo '/ calc trait /'; } } class MyClass { use A; function calc($v) { echo '/ calc class /'; parent::calc1(5); //parent::calc($v); } } $x=new MyClass(); $x->calc(123);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Cannot use "parent" when current class scope has no parent in /in/gjokM on line 16
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Cannot use "parent" when current class scope has no parent in /in/gjokM on line 16 / calc class / Fatal error: Uncaught Error: Cannot access parent:: when current class scope has no parent in /in/gjokM:16 Stack trace: #0 /in/gjokM(22): MyClass->calc(123) #1 {main} thrown in /in/gjokM 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.33
/ calc class / Fatal error: Uncaught Error: Cannot access parent:: when current class scope has no parent in /in/gjokM:16 Stack trace: #0 /in/gjokM(22): MyClass->calc(123) #1 {main} thrown in /in/gjokM on line 16
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
/ calc class / Fatal error: Cannot access parent:: when current class scope has no parent in /in/gjokM on line 16
Process exited with code 255.

preferences:
234.02 ms | 402 KiB | 270 Q