Skip to content

Commit cb173f5

Browse files
committed
Zend: Inherit interfaces early
1 parent ea26562 commit cb173f5

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

1584-
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
1584+
static inline void do_implement_interface_ex(zend_class_entry *ce, zend_class_entry *inherited_face, zend_class_entry *base_iface)
15851585
{
1586-
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && iface->interface_gets_implemented && iface->interface_gets_implemented(iface, ce) == FAILURE) {
1587-
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));
1586+
if (!(ce->ce_flags & ZEND_ACC_INTERFACE) && inherited_face->interface_gets_implemented && inherited_face->interface_gets_implemented(base_iface, ce) == FAILURE) {
1587+
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));
15881588
}
15891589
/* This should be prevented by the class lookup logic. */
1590-
ZEND_ASSERT(ce != iface);
1590+
ZEND_ASSERT(ce != base_iface);
1591+
}
1592+
1593+
static inline void do_implement_interface(zend_class_entry *ce, zend_class_entry *iface)
1594+
{
1595+
do_implement_interface_ex(ce, iface, iface);
15911596
}
1592-
/* }}} */
15931597

1594-
static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface) /* {{{ */
1598+
static void zend_do_inherit_interfaces(zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
15951599
{
15961600
/* expects interface to be contained in ce's interface list already */
15971601
uint32_t i, ce_num, if_num = iface->num_interfaces;
@@ -1620,7 +1624,7 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
16201624

16211625
/* and now call the implementing handlers */
16221626
while (ce_num < ce->num_interfaces) {
1623-
do_implement_interface(ce, ce->interfaces[ce_num++]);
1627+
do_implement_interface_ex(ce, ce->interfaces[ce_num++], iface);
16241628
}
16251629
}
16261630
/* }}} */
@@ -2155,6 +2159,10 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
21552159
zend_class_constant *c;
21562160
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;
21572161

2162+
if (iface->num_interfaces) {
2163+
zend_do_inherit_interfaces(ce, iface);
2164+
}
2165+
21582166
if (!(ce->ce_flags & ZEND_ACC_INTERFACE)) {
21592167
/* We are not setting the prototype of overridden interface methods because of abstract
21602168
* constructors. See Zend/tests/interface_constructor_prototype_001.phpt. */
@@ -2186,9 +2194,6 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
21862194
} ZEND_HASH_FOREACH_END();
21872195

21882196
do_implement_interface(ce, iface);
2189-
if (iface->num_interfaces) {
2190-
zend_do_inherit_interfaces(ce, iface);
2191-
}
21922197
}
21932198
/* }}} */
21942199

0 commit comments

Comments
 (0)