php.net |  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: 2016-10-21 15:57 UTC
From: mkh117 at gmail dot com Assigned:
Status: Verified Package: Class/Object related
PHP Version: 7.0.12 OS: Ubuntu 16.04.1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-10-19 13:08 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-19 15:17 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-10-19 15:17 UTC] cmb@php.net
Confirmed: <https://3v4l.org/u4Y1q>.
 [2016-10-21 15:42 UTC] 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-21 15:57 UTC] leigh@php.net
Actually that might not be a bug, possibly designed to prevent:

class B implements A, A {}
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Mar 26 04:01:27 2019 UTC