Skip to content

Commit 37eab80

Browse files
committed
Zend: Inherit interfaces early
1 parent 2269951 commit 37eab80

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
@@ -1579,17 +1579,21 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
15791579
}
15801580
/* }}} */
15811581

1582-
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
1582+
static inline void do_implement_interface_ex(zend_class_entry *ce, zend_class_entry *inherited_face, zend_class_entry *base_iface)
15831583
{
1584-
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && iface->interface_gets_implemented && iface->interface_gets_implemented(iface, ce) == FAILURE) {
1585-
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));
1584+
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && inherited_face->interface_gets_implemented && inherited_face->interface_gets_implemented(base_iface, ce) == FAILURE) {
1585+
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));
15861586
}
15871587
/* This should be prevented by the class lookup logic. */
1588-
ZEND_ASSERT(ce != iface);
1588+
ZEND_ASSERT(ce != base_iface);
1589+
}
1590+
1591+
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface)
1592+
{
1593+
do_implement_interface_ex(ce, iface, iface);
15891594
}
1590-
/* }}} */
15911595

1592-
static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface) /* {{{ */
1596+
static void zend_do_inherit_interfaces(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
15931597
{
15941598
/* expects interface to be contained in ce's interface list already */
15951599
uint32_t i, ce_num, if_num = iface->num_interfaces;
@@ -1618,7 +1622,7 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
16181622

16191623
/* and now call the implementing handlers */
16201624
while (ce_num < ce->num_interfaces) {
1621-
do_implement_interface(ce, ce->interfaces[ce_num++]);
1625+
do_implement_interface_ex(ce, ce->interfaces[ce_num++], iface);
16221626
}
16231627
}
16241628
/* }}} */
@@ -2168,6 +2172,10 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
21682172
zend_class_constant *c;
21692173
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;
21702174

2175+
if (iface->num_interfaces) {
2176+
zend_do_inherit_interfaces(ce, iface);
2177+
}
2178+
21712179
if (!(ce->ce_flags & ZEND_ACC_INTERFACE)) {
21722180
/* We are not setting the prototype of overridden interface methods because of abstract
21732181
* constructors. See Zend/tests/interface_constructor_prototype_001.phpt. */
@@ -2199,9 +2207,6 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
21992207
} ZEND_HASH_FOREACH_END();
22002208

22012209
do_implement_interface(ce, iface);
2202-
if (iface->num_interfaces) {
2203-
zend_do_inherit_interfaces(ce, iface);
2204-
}
22052210
}
22062211
/* }}} */
22072212

0 commit comments

Comments
 (0)