|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73348 A class can override a constant inherited from an indirect parent interface.
Submitted: 2016-10-19 13:08 UTC Modified: 2021-11-18 22:28 UTC
Avg. Score:3.7 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:2 (40.0%)
From: mkh117 at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 7.0.12 OS: Ubuntu 16.04.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mkh117 at gmail dot com
New email:
PHP Version: OS:


 [2016-10-19 13:08 UTC] mkh117 at gmail dot com
When a class inherits a constant from an interface that is not a direct parent of the class, it can override its value without any errors thrown.

Test script:
interface a {
  const con = 'Original value';	

abstract class b implements a {


class d extends b {
  const con='Overridden value';

echo d::con;

Expected result:
Fatal error:  Cannot inherit previously-inherited constant con from interface a ... on line 11

Actual result:
The script works and the interface constant is overridden.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-19 15:17 UTC]
-Status: Open +Status: Verified
 [2016-10-19 15:17 UTC]
Confirmed: <>.
 [2016-10-21 15:42 UTC]

interface A {}
abstract class B implements A {}
class C extends B implements A {}

I would expect this to generate: "Class %s cannot implement previously implemented interface %s"

Both this and the constant override issue are handled by zend_do_implement_interface which is not called for for grandchildren implementors
 [2016-10-21 15:57 UTC]
Actually that might not be a bug, possibly designed to prevent:

class B implements A, A {}
 [2021-09-23 15:00 UTC] dktapps at pmmp dot io
Is there any discussion on what to do about this problem? I just learned that a project of mine (with an API stable for 3 years) unintentionally exploited this bug, so I'd love to get an idea of whether I need to break BC to avoid my house burning down on a patch release.
 [2021-11-18 22:28 UTC]
-Status: Verified +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-11-18 22:28 UTC]
Actually, this is not a bug, but rather the fact that constants
defined in interfaces could not be overridden was.  This is all
resolved as of PHP 8.1.0[1] due to the introduction of final

> […], so I'd love to get an idea of whether I need to break BC to
> avoid my house burning down on a patch release.

No worries. :)

[1] <>
[2] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 10:01:31 2024 UTC