Edit report at https://bugs.php.net/bug.php?id=65576&edit=1
ID: 65576 Updated by: ahar...@php.net Reported by: krewecherl at gmail dot com Summary: Constructor from trait conflicts with inherited constructor Status: Open Type: Bug Package: Class/Object related Operating System: * PHP Version: 5.4.19 -Assigned To: +Assigned To: gron Block user comment: N Private report: N New Comment: Stefan, since you fixed the original bug, do you have any thoughts on this one? Previous Comments: ------------------------------------------------------------------------ [2013-08-28 20:49:06] krewecherl at gmail dot com Description: ------------ Given: - a trait T containing a __construct method - a base class A with a __construct method (directly, inherited or via traits) - a class B exending A and using trait T Compilation fails with the fatal error "B has colliding constructor definitions coming from traits". Any other method (including magic methods like __set) works fine in this scenario, with the constructor being the only exception. It should be possible to use a constructor from a trait in a derived class, even if the base class already has a constructor. The collision can be resolved by prioritizing the constructor from the trait over the inherited constructor. This problem is the result of a bugfix in zend_compile.c related to issue #55554 (Trait methods overriding legacy constructors): https://github.com/php/php-src/commit/e14354af21c9188582ef454696163cf68c7677ce I understand the problem, but think that the given combination should still be made to work. If there are insurmountable technical difficulties, the special exception for constructors needs to be documented in the manual. Test script: --------------- trait T { public function __construct () {} } class A { public function __construct () {} } class B extends A { use T; } Expected result: ---------------- Class B uses the constructor included via trait T, overriding base class A's original constructor. Actual result: -------------- Fatal error "B has colliding constructor definitions coming from traits". ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65576&edit=1