Skip to content

Commit 229fcc9

Browse files
committed
Zend: Inherit interfaces early
1 parent 439458c commit 229fcc9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Zend/zend_inheritance.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,17 +1724,21 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
17241724
}
17251725
/* }}} */
17261726

1727-
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
1727+
static inline void do_implement_interface_ex(zend_class_entry *ce, zend_class_entry *inherited_face, zend_class_entry *base_iface)
17281728
{
1729-
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && iface->interface_gets_implemented && iface->interface_gets_implemented(iface, ce) == FAILURE) {
1730-
zend_error_noreturn(E_CORE_ERROR, "%s %s could not implement interface %s", zend_get_object_type_uc(ce), ZSTR_VAL(ce->name), ZSTR_VAL(iface->name));
1729+
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && inherited_face->interface_gets_implemented && inherited_face->interface_gets_implemented(base_iface, ce) == FAILURE) {
1730+
zend_error_noreturn(E_CORE_ERROR, "%s %s could not implement interface %s", zend_get_object_type_uc(ce), ZSTR_VAL(ce->name), ZSTR_VAL(base_iface->name));
17311731
}
17321732
/* This should be prevented by the class lookup logic. */
1733-
ZEND_ASSERT(ce != iface);
1733+
ZEND_ASSERT(ce != base_iface);
1734+
}
1735+
1736+
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface)
1737+
{
1738+
do_implement_interface_ex(ce, iface, iface);
17341739
}
1735-
/* }}} */
17361740

1737-
static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface) /* {{{ */
1741+
static void zend_do_inherit_interfaces(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
17381742
{
17391743
/* expects interface to be contained in ce's interface list already */
17401744
uint32_t i, ce_num, if_num = iface->num_interfaces;
@@ -1764,7 +1768,7 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
17641768

17651769
/* and now call the implementing handlers */
17661770
while (ce_num < ce->num_interfaces) {
1767-
do_implement_interface(ce, ce->interfaces[ce_num++]);
1771+
do_implement_interface_ex(ce, ce->interfaces[ce_num++], iface);
17681772
}
17691773
}
17701774
/* }}} */
@@ -2406,6 +2410,10 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
24062410
zend_class_constant *c;
24072411
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;
24082412

2413+
if (iface->num_interfaces) {
2414+
zend_do_inherit_interfaces(ce, iface);
2415+
}
2416+
24092417
if (!(ce->ce_flags & ZEND_ACC_INTERFACE)) {
24102418
/* We are not setting the prototype of overridden interface methods because of abstract
24112419
* constructors. See Zend/tests/interface_constructor_prototype_001.phpt. */
@@ -2525,9 +2533,6 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
25252533
} ZEND_HASH_FOREACH_END();
25262534

25272535
do_implement_interface(ce, iface);
2528-
if (iface->num_interfaces) {
2529-
zend_do_inherit_interfaces(ce, iface);
2530-
}
25312536
}
25322537
/* }}} */
25332538

0 commit comments

Comments
 (0)