mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Zend: inherit interfaces early (#18622)
The primary motivation for this is that this is required for my abstract generic types proof of concept, as the resolving of bound types needs to happen early to properly track the types. However, there doesn't seem to be a good reason for delaying the inheritance of interfaces. This approach might even allow us to drop the `iface` parameter of the `interface_gets_implemented()` handler as the interface name is always known.
This commit is contained in:
committed by
GitHub
parent
1096ea149a
commit
f93b17076a
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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. */
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user