Bug #73348 [Ver->Nab]: A class can override a constant inherited from an indirect parent interface.
| From: | cmb@php.net | Date: | Thu, 18 Nov 2021 22:28:25 +0000 |
| Subject: | Bug #73348 [Ver->Nab]: A class can override a constant inherited from an indirect parent interface. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237860@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73348&edit=1
ID: 73348
Updated by: cmb@php.net
Reported by: mkh117 at gmail dot com
Summary: A class can override a constant inherited from an
indirect parent interface.
-Status: Verified
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Ubuntu 16.04.1
PHP Version: 7.0.12
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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
constants[2].
> [â¦], 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] <https://3v4l.org/c5dmY>
[2] <https://wiki.php.net/rfc/final_class_const>
Previous Comments:
------------------------------------------------------------------------
[2021-09-23 15:00:38] 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.
------------------------------------------------------------------------
[2016-10-21 15:57:30] leigh@php.net
Actually that might not be a bug, possibly designed to prevent:
class B implements A, A {}
------------------------------------------------------------------------
[2016-10-21 15:42:29] leigh@php.net
Related:
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-19 15:17:45] cmb@php.net
Confirmed: <https://3v4l.org/u4Y1q>.
------------------------------------------------------------------------
[2016-10-19 13:08:33] mkh117 at gmail dot com
Description:
------------
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:
---------------
<?php
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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73348&edit=1