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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC