|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-03-05 13:30 UTC] korikulum at net dot hr
[2018-03-05 13:38 UTC] daverandom@php.net
-Status: Open
+Status: Duplicate
[2018-03-05 13:38 UTC] daverandom@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
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.