3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ATrait { public function a(){ return 'Aa'; } } trait BTrait { public function a(){ return 'Ba'; } } class C { use ATrait{ a as aa; } use BTrait{ a as ba; } public function a() { return static::aa() . static::ba(); } } $o = new C; echo $o->a(), "\n"; class D { use ATrait{ ATrait::a as aa; } use BTrait{ BTrait::a as ba; } public function a() { return static::aa() . static::ba(); } } $o = new D; echo $o->a(), "\n"; class E { use ATrait{ ATrait::a as aa; ATrait::a insteadof BTrait; } use BTrait{ BTrait::a as ba; } public function e() { return static::aa() . static::ba(); } } $o = new E; echo $o->e(), "\n"; class F { use ATrait{ a as aa; } use BTrait{ a as ba; } public function f() { return static::aa() . static::ba(); } } $o = new F; echo $o->f(), "\n";
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.4, 8.3.6
Fatal error: An alias was defined for method a(), which exists in both ATrait and BTrait. Use ATrait::a or BTrait::a to resolve the ambiguity in /in/mFuQE on line 15
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: An alias was defined for method a(), which exists in both ATrait and BTrait. Use ATrait::a or BTrait::a to resolve the ambiguity in /in/mFuQE on line 15
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
AaAa AaBa Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; E has a deprecated constructor in /in/mFuQE on line 48 AaBa Fatal error: Trait method a has not been applied, because there are collisions with other trait methods on F in /in/mFuQE on line 65
Process exited with code 255.
Output for 5.6.0 - 5.6.40
AaAa AaBa AaBa Fatal error: Trait method a has not been applied, because there are collisions with other trait methods on F in /in/mFuQE on line 76
Process exited with code 255.

preferences:
211.3 ms | 401 KiB | 300 Q