3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Basic{ public function sayHello($name){ echo 'Hello world! I am '.$name; } } trait TraitMethod{ public function sayHello($name){ echo 'Hello! My name is '.$name; } } class TestC extends Basic{ use TraitMethod; public function sayHello($name){ parent::sayHello($name); TraitMethod::sayHello($name); } } $objTestC = new TestC(); $objTestC->sayHello("Anna");
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Hello world! I am Anna Deprecated: Calling static trait method TraitMethod::sayHello is deprecated, it should only be called on a class using the trait in /in/KPVBC on line 20 Fatal error: Uncaught Error: Non-static method TraitMethod::sayHello() cannot be called statically in /in/KPVBC:20 Stack trace: #0 /in/KPVBC(25): TestC->sayHello('Anna') #1 {main} thrown in /in/KPVBC on line 20
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Hello world! I am Anna Fatal error: Uncaught Error: Non-static method TraitMethod::sayHello() cannot be called statically in /in/KPVBC:20 Stack trace: #0 /in/KPVBC(25): TestC->sayHello('Anna') #1 {main} thrown in /in/KPVBC on line 20
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
Hello world! I am Anna Deprecated: Non-static method TraitMethod::sayHello() should not be called statically in /in/KPVBC on line 20 Hello! My name is Anna
Output for 7.3.32 - 7.3.33
Hello world! I am AnnaHello! My name is Anna
Output for 5.6.8 - 5.6.28
Hello world! I am Anna Deprecated: Non-static method TraitMethod::sayHello() should not be called statically, assuming $this from incompatible context in /in/KPVBC on line 20 Hello! My name is Anna
Output for 5.5.24 - 5.5.35
Hello world! I am Anna Strict Standards: Non-static method TraitMethod::sayHello() should not be called statically, assuming $this from incompatible context in /in/KPVBC on line 20 Hello! My name is Anna

preferences:
161.83 ms | 402 KiB | 183 Q