|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70710 Method compatible declaration issue with parent of class when using trait
Submitted: 2015-10-14 10:12 UTC Modified: 2015-10-15 20:55 UTC
From: wouter at wouter0100 dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: wouter at wouter0100 dot nl
New email:
PHP Version: OS:


 [2015-10-14 10:12 UTC] wouter at wouter0100 dot nl
When you extend a class and use a trait with the same method, you'll get a declaration error. Only by overwriting the extended classes method within the class itself, this is fixed.

Test script:
Method test:
Declaration error:

Current workaround:

Expected result:
That the (strict) warning isn't being shown and I'm able to execute $this->execute for the parents method and $this->executeTrait for the trait's method.

Actual result:
See tests.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-15 20:50 UTC]
-Status: Open +Status: Not a bug
 [2015-10-15 20:50 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP is not supporting method overloading.
And it requires declarations to match (Liskov Substitution principle needs to hold: each value I can pass to a parent class must also be allowed to be passed to a child class),

P.s.: In case of a declaration warning, the method is not added at all.
 [2015-10-15 20:55 UTC]
Addendum: note that use ... as ...; instructions in traits are pure aliases. The method with the original name still exists in the class.

See also: (execute() and executeTrait() are defined)

This is necessary, so that calls between methods inside traits don't break, as traits don't declare their own scope, but are pure compiler-assisted copy&paste.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC