|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62204 Final keyword not enforced for methods from traits
Submitted: 2012-06-01 07:53 UTC Modified: 2021-09-16 11:53 UTC
Avg. Score:4.0 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 5.4Git-2012-06-01 (Git) 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:
New email:
PHP Version: OS:


 [2012-06-01 07:53 UTC]
Reported by Scott MacVicar on the mailing list (May 4th).
Added here to not forget about it.

> On 04 May 2012, at 20:30, Scott MacVicar wrote:
> This caused a few bugs for us / confusion. The final keyword is accepted 
inside a trait but it the class also 
defines a method without the final keyword this takes precedence.
> Two solutions:
> Enforce final when a trait defines -
> Prohibit final form being used in a trait -
> I'm for the first solution here
> - S


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-03 17:21 UTC]
-Status: Open +Status: Assigned -Package: *Compile Issues +Package: Scripting Engine problem -Assigned To: +Assigned To: gron
 [2013-03-19 12:30 UTC] wolters dot fl at gmail dot com
This bug still exists in PHP version 5.4.13. I've created a simple example at to reproduce the behaviour described in the bug report.

IMHO the "final" keyword MUST be enforced when used in a trait.
 [2013-06-03 12:28 UTC] alasdair at softhome dot net
Still exists in PHP 5.4.4-14 on Debian Wheezy.
 [2017-10-24 07:04 UTC]
-Status: Assigned +Status: Open -Assigned To: gron +Assigned To:
 [2021-09-16 11:53 UTC]
-Status: Open +Status: Verified
 [2021-09-16 11:53 UTC]
Still unresolved: <>.
 [2021-12-06 22:57 UTC]
When the method is defined in both the trait and the current class the method isn't "overridden" per se (even though the docs word it this way) but rather the trait method is discarded.

For the same reason LSP isn't validated either.

IMO we should fix both or neither. But I'm leaning towards the latter.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 09:01:28 2024 UTC