|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-12-01 11:31 UTC] laruence@php.net
-Status: Open
+Status: Wont fix
[2012-12-01 11:31 UTC] laruence@php.net
[2012-12-01 12:19 UTC] nikic@php.net
[2012-12-02 14:05 UTC] phpbugs at catchall dot drarok dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
Description: ------------ If you use a Trait which has a method name matching your class name, it is used as an old-style constructor in the case where the using class doesn't define a constructor. If you *do* define a constructor, you receive the error "Fatal error: Hello has colliding constructor definitions coming from traits". Test script: --------------- <?php trait HelloWorld { public function hello() { echo 'Hello, World!', PHP_EOL; } static public function world() { echo 'World; Hello!', PHP_EOL; } } class Hello { use HelloWorld; } class World { use HelloWorld; } new Hello(); new World(); /* * # php example.php * Hello, World! * World; Hello! */ Expected result: ---------------- Given that Traits cannot be used in legacy code, I'd expect the method name to be irrelevant to constructor behaviour. Actual result: -------------- Method names that match the class name are used as a constructor.