Skip to content

Commit c454a3b

Browse files
committed
Perform full implementation check at runtime
1 parent 01af74c commit c454a3b

File tree

2 files changed

+7
-80
lines changed

2 files changed

+7
-80
lines changed

Zend/tests/type_declarations/variance/enum_forward_compat.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class B extends A {
2222

2323
?>
2424
--EXPECT--
25-
string(1) "Y"
2625
string(1) "X"
26+
string(1) "Y"

Zend/zend_inheritance.c

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,11 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
760760
}
761761
}
762762

763-
/* TODO Properly handle UNRESOLVED. */
764-
765-
/*
766-
if (status == INHERITANCE_UNRESOLVED && CG(unverified_types)) {
767-
zend_string *key = zend_string_tolower(fe->common.scope->name);
763+
if (status == INHERITANCE_UNRESOLVED && CG(unverified_types)) {
764+
zend_string *key = zend_string_tolower(child->common.scope->name);
768765
zend_hash_add_empty_element(CG(unverified_types), key);
769766
zend_string_release(key);
770-
}
771-
*/
767+
}
772768
}
773769
} while (0);
774770
}
@@ -2222,9 +2218,8 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce)
22222218
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
22232219

22242220
ZEND_HASH_FOREACH_PTR(&ce->function_table, child) {
2225-
zend_function *parent = child->common.prototype;
2226-
22272221
/* Methods without prototypes do not need checked for variance. */
2222+
zend_function *parent = child->common.prototype;
22282223
if (!parent) {
22292224
continue;
22302225
}
@@ -2236,76 +2231,8 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce)
22362231
continue;
22372232
}
22382233

2239-
/* We are only willing to ignore this for internal functions because
2240-
* extensions don't always define arg_info. */
2241-
if (missing_internal_arginfo(parent)) {
2242-
continue;
2243-
}
2244-
2245-
/* If the parenttype method is private do not enforce a signature */
2246-
if (!(parent->common.fn_flags & ZEND_ACC_PRIVATE)) {
2247-
uint32_t i, num_args;
2248-
2249-
/* Checks for constructors only if they are declared in an interface,
2250-
* or explicitly marked as abstract
2251-
*/
2252-
if ((ce->constructor == child)
2253-
&& ((parent->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0
2254-
&& (parent->common.fn_flags & ZEND_ACC_ABSTRACT) == 0))
2255-
{
2256-
continue;
2257-
}
2258-
2259-
/* Check return type compatibility, but only if the prototype already
2260-
* specifies a return type. Adding a new return type is always valid. */
2261-
if (parent->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
2262-
if (child->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
2263-
inheritance_status status = check_inherited_return_type(
2264-
child, &child->common.arg_info[-1],
2265-
parent, &parent->common.arg_info[-1]);
2266-
if (status != INHERITANCE_SUCCESS) {
2267-
inheritance_runtime_error_msg(child, parent);
2268-
continue;
2269-
}
2270-
} else {
2271-
// This branch should already have been taken care of
2272-
continue;
2273-
}
2274-
}
2275-
2276-
if (parent->common.required_num_args < child->common.required_num_args
2277-
|| parent->common.num_args > child->common.num_args)
2278-
{
2279-
// This branch should already have been taken care of
2280-
continue;
2281-
}
2282-
2283-
num_args = parent->common.num_args;
2284-
if (parent->common.fn_flags & ZEND_ACC_VARIADIC) {
2285-
num_args++;
2286-
if (child->common.num_args >= parent->common.num_args) {
2287-
num_args = child->common.num_args;
2288-
if (child->common.fn_flags & ZEND_ACC_VARIADIC) {
2289-
num_args++;
2290-
}
2291-
}
2292-
}
2293-
2294-
for (i = 0; i < num_args; i++) {
2295-
zend_arg_info *child_arg_info = &child->common.arg_info[i];
2296-
zend_arg_info *parent_arg_info = (i < parent->common.num_args)
2297-
? &parent->common.arg_info[i]
2298-
: &parent->common.arg_info[parent->common.num_args];
2299-
2300-
inheritance_status status = check_inherited_parameter_type(
2301-
child, child_arg_info,
2302-
parent, parent_arg_info);
2303-
if (status != INHERITANCE_SUCCESS) {
2304-
inheritance_runtime_error_msg(child, parent);
2305-
continue;
2306-
}
2307-
}
2308-
2234+
if (zend_do_perform_implementation_check(child, parent) != INHERITANCE_SUCCESS) {
2235+
inheritance_runtime_error_msg(child, parent);
23092236
}
23102237
} ZEND_HASH_FOREACH_END();
23112238

0 commit comments

Comments
 (0)