Bug #76051 [Opn->Dup]: Inconsistent behavior with overriding constants in interfaces

From: Date: Mon, 05 Mar 2018 13:38:27 +0000
Subject: Bug #76051 [Opn->Dup]: Inconsistent behavior with overriding constants in interfaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214202@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 Updated by: daverandom@php.net Reported by: korikulum at net dot hr Summary: Inconsistent behavior with overriding constants in interfaces -Status: Open +Status: Duplicate Type: Bug Package: Class/Object related PHP Version: 7.1.15 Block user comment: N Private report: N New Comment: Duplicate of https://bugs.php.net/bug.php?id=73348 Previous Comments: ------------------------------------------------------------------------ [2018-03-05 13:30:44] korikulum at net dot hr Update ------------------------------------------------------------------------ [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

« previous php.bugs (#214202) next »