Bugs php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login

go to bug id or search bugs for

Bug #62204 Final keyword not enforced for methods from traits
Submitted: 2012年06月01日 07:53 UTC Modified: 2021年09月16日 11:53 UTC
Votes:8
Avg. Score:4.0 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: gron@php.net Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 5.4Git-2012年06月01日 (Git) OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gron@php.net
New email:
PHP Version: OS:

[2012年06月01日 07:53 UTC] gron@php.net
Description:
------------
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 - https://whisky.macvicar.net/patches/0001-
If-a-trait-declares-a-method-
as-final-enforce-that.patch
> 
> Prohibit final form being used in a trait - 
https://whisky.macvicar.net/patches/002-traits-Disable-use-of-
final-keyword.patch
> 
> I'm for the first solution here
> 
> - S

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
[2012年06月03日 17:21 UTC] felipe@php.net
-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 https://gist.github.com/FlorianWolters/5195674 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] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: gron +Assigned To:
[2021年09月16日 11:53 UTC] cmb@php.net
-Status: Open +Status: Verified
[2021年09月16日 11:53 UTC] cmb@php.net
Still unresolved: <https://3v4l.org/fG69k>.
[2021年12月06日 22:57 UTC] ilutov@php.net
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. https://3v4l.org/RZB2K
IMO we should fix both or neither. But I'm leaning towards the latter.
PHP Copyright © 2001-2025 The PHP Group
All rights reserved. Last updated: Thu Oct 16 21:00:02 2025 UTC

AltStyle によって変換されたページ (->オリジナル) /