Bug #76051 [Opn]: Inconsistent behavior with overriding constants in interfaces
| From: | korikulum at net dot hr | Date: | Mon, 05 Mar 2018 13:30:45 +0000 |
| Subject: | Bug #76051 [Opn]: Inconsistent behavior with overriding constants in interfaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214201@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76051&edit=1
ID: 76051
User updated by: korikulum at net dot hr
Reported by: korikulum at net dot hr
Summary: Inconsistent behavior with overriding constants in
interfaces
Status: Open
Type: Bug
Package: Class/Object related
PHP Version: 7.1.15
Block user comment: N
Private report: N
New Comment:
Update
Previous Comments:
------------------------------------------------------------------------
[2018-03-05 13:28:06] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76051&edit=1