php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76051 Inconsistent behavior with overriding constants in interfaces
Submitted: 2018-03-05 13:28 UTC Modified: 2018-03-05 13:38 UTC
From: korikulum at net dot hr Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 7.1.15 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: korikulum at net dot hr
New email:
PHP Version: OS:

 

 [2018-03-05 13:28 UTC] korikulum at net dot hr
Description:
------------
Overriding constants defined in interfaces isn't allowed in classes that implement the interface, but is in classes that extend classes that implement the interface.

Test script:
---------------
<?php

interface FooInterface
{
    const BAR = '';
}

class Foo implements FooInterface
{
    const BAR = 'BAR';
}

$baz = new Foo;

var_dump($baz::BAR);

https://3v4l.org/qVreY


<?php

interface FooInterface
{
    const BAR = '';
}

abstract class AbstractFoo implements FooInterface
{
    
}

class Foo extends AbstractFoo
{
    const BAR = 'BAR';
}

$baz = new Foo;

var_dump($baz::BAR);

https://3v4l.org/9S53j

Expected result:
----------------
Either both cases work or both result in the error "Fatal error: Cannot inherit previously-inherited or override constant SOME_CONST from interface MyInterface".

Actual result:
--------------
The first case gives the error "Fatal error: Cannot inherit previously-inherited or override constant SOME_CONST from interface MyInterface".

The second case works normally.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-05 13:30 UTC] korikulum at net dot hr
Update
 [2018-03-05 13:38 UTC] daverandom@php.net
-Status: Open +Status: Duplicate
 [2018-03-05 13:38 UTC] daverandom@php.net
Duplicate of https://bugs.php.net/bug.php?id=73348
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 15:01:27 2025 UTC