Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/enum/no-class-implements-backed-enum.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class Foo implements BackedEnum {}

?>
--EXPECTF--
Fatal error: Non-enum class Foo cannot implement interface BackedEnum in %s on line %d
Fatal error: Non-enum class Foo cannot implement interface UnitEnum in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Interface that is extended from Enum only interface shouldn't be implementable by non-enum class
--FILE--
<?php
interface I extends UnitEnum {}

class C implements I {
public static function cases(): array {
return [];
}
}

?>
--EXPECTF--
Fatal error: Non-enum class C cannot implement interface UnitEnum in %s on line %d
7 changes: 4 additions & 3 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,10 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
zend_class_constant *c;
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;

if (iface->num_interfaces) {
zend_do_inherit_interfaces(ce, iface);
}

if (!(ce->ce_flags & ZEND_ACC_INTERFACE)) {
/* We are not setting the prototype of overridden interface methods because of abstract
* constructors. See Zend/tests/interface_constructor_prototype_001.phpt. */
Expand Down Expand Up @@ -2199,9 +2203,6 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
} ZEND_HASH_FOREACH_END();

do_implement_interface(ce, iface);
if (iface->num_interfaces) {
zend_do_inherit_interfaces(ce, iface);
}
}
/* }}} */

Expand Down
Loading