@@ -273,7 +273,7 @@ typedef enum {
273
273
* the fact that they are inverses to improve correctness and simplify code.
274
274
* We can implement covariance, and then implement contravariance simply by
275
275
* reversing the argument order. */
276
- static inheritance_status _check_covariance (
276
+ static inheritance_status check_covariance (
277
277
const zend_function * fe , zend_arg_info * fe_arg_info ,
278
278
const zend_function * proto , zend_arg_info * proto_arg_info )
279
279
{ /* {{{ */
@@ -346,7 +346,7 @@ static inheritance_status _check_covariance(
346
346
}
347
347
/* }}} */
348
348
349
- static inheritance_status _check_inherited_return_type (
349
+ static inheritance_status check_inherited_return_type (
350
350
const zend_function * fe , zend_arg_info * fe_arg_info ,
351
351
const zend_function * proto , zend_arg_info * proto_arg_info ) /* {{{ */
352
352
{
@@ -355,21 +355,20 @@ static inheritance_status _check_inherited_return_type(
355
355
return INHERITANCE_ERROR ;
356
356
}
357
357
358
- return _check_covariance (fe , fe_arg_info , proto , proto_arg_info );
358
+ return check_covariance (fe , fe_arg_info , proto , proto_arg_info );
359
359
}
360
360
361
-
362
- static zend_bool _missing_internal_arginfo (zend_function const * fn )
361
+ static zend_bool missing_internal_arginfo (zend_function const * fn )
363
362
{
364
363
return !fn -> common .arg_info && fn -> common .type == ZEND_INTERNAL_FUNCTION ;
365
364
}
366
365
367
- static inheritance_status _check_inherited_parameter_type (
366
+ static inheritance_status check_inherited_parameter_type (
368
367
const zend_function * fe , zend_arg_info * fe_arg_info ,
369
368
const zend_function * proto , zend_arg_info * proto_arg_info ) /* {{{ */
370
369
{
371
370
372
- /* by -ref constraints on arguments are invariant */
371
+ /* By -ref constraints on arguments are invariant */
373
372
if (fe_arg_info -> pass_by_reference != proto_arg_info -> pass_by_reference ) {
374
373
return INHERITANCE_ERROR ;
375
374
}
@@ -385,7 +384,7 @@ static inheritance_status _check_inherited_parameter_type(
385
384
}
386
385
387
386
/* CONTRAVARIANT is inverse of COVARIANT, so call with reversed args. */
388
- return _check_covariance (proto , proto_arg_info , fe , fe_arg_info );
387
+ return check_covariance (proto , proto_arg_info , fe , fe_arg_info );
389
388
}
390
389
/* }}} */
391
390
@@ -399,7 +398,7 @@ static inheritance_status zend_do_perform_implementation_check(
399
398
* we still need to do the arg number checks. We are only willing to ignore this for internal
400
399
* functions because extensions don't always define arg_info.
401
400
*/
402
- if (_missing_internal_arginfo (proto )) {
401
+ if (missing_internal_arginfo (proto )) {
403
402
return INHERITANCE_SUCCESS ;
404
403
}
405
404
@@ -458,7 +457,7 @@ static inheritance_status zend_do_perform_implementation_check(
458
457
: & proto -> common .arg_info [proto -> common .num_args ];
459
458
460
459
inheritance_status local_status =
461
- _check_inherited_parameter_type (fe , fe_arg_info , proto , proto_arg_info );
460
+ check_inherited_parameter_type (fe , fe_arg_info , proto , proto_arg_info );
462
461
if (local_status == INHERITANCE_ERROR ) {
463
462
return INHERITANCE_ERROR ;
464
463
} else if (local_status == INHERITANCE_UNRESOLVED ) {
@@ -470,7 +469,7 @@ static inheritance_status zend_do_perform_implementation_check(
470
469
* a return type. Adding a new return type is always valid. */
471
470
if (proto -> common .fn_flags & ZEND_ACC_HAS_RETURN_TYPE ) {
472
471
inheritance_status local_result =
473
- _check_inherited_return_type (
472
+ check_inherited_return_type (
474
473
fe , fe -> common .arg_info - 1 , proto , proto -> common .arg_info - 1 );
475
474
if (local_result == INHERITANCE_ERROR ) {
476
475
return INHERITANCE_ERROR ;
@@ -750,7 +749,7 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
750
749
error_level = E_COMPILE_ERROR ;
751
750
error_verb = "must" ;
752
751
} else if ((parent -> common .fn_flags & ZEND_ACC_HAS_RETURN_TYPE ) &&
753
- !_check_inherited_return_type (child , child -> common .arg_info - 1 , parent , parent -> common .arg_info - 1 )) {
752
+ !check_inherited_return_type (child , child -> common .arg_info - 1 , parent , parent -> common .arg_info - 1 )) {
754
753
error_level = E_COMPILE_ERROR ;
755
754
error_verb = "must" ;
756
755
} else {
@@ -2181,15 +2180,15 @@ ZEND_API void zend_do_link_class(zend_class_entry *ce, zend_class_entry *parent)
2181
2180
}
2182
2181
/* }}} */
2183
2182
2184
- static void _inheritance_runtime_error_msg (zend_function * child , zend_function * parent )
2183
+ static void inheritance_runtime_error_msg (zend_function * child , zend_function * parent )
2185
2184
{
2186
2185
int level = E_WARNING ;
2187
2186
const char * verb = "should" ;
2188
2187
ZEND_ASSERT (child && parent );
2189
2188
if ((parent -> common .fn_flags & ZEND_ACC_ABSTRACT )
2190
2189
|| (
2191
2190
(parent -> common .fn_flags & ZEND_ACC_HAS_RETURN_TYPE )
2192
- && _check_inherited_return_type (child , child -> common .arg_info - 1 ,
2191
+ && check_inherited_return_type (child , child -> common .arg_info - 1 ,
2193
2192
parent , parent -> common .arg_info - 1 ) != INHERITANCE_SUCCESS
2194
2193
))
2195
2194
{
@@ -2232,7 +2231,7 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce)
2232
2231
2233
2232
/* We are only willing to ignore this for internal functions because
2234
2233
* extensions don't always define arg_info. */
2235
- if (_missing_internal_arginfo (parent )) {
2234
+ if (missing_internal_arginfo (parent )) {
2236
2235
continue ;
2237
2236
}
2238
2237
@@ -2254,11 +2253,13 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce)
2254
2253
* specifies a return type. Adding a new return type is always valid. */
2255
2254
if (parent -> common .fn_flags & ZEND_ACC_HAS_RETURN_TYPE ) {
2256
2255
if (child -> common .fn_flags & ZEND_ACC_HAS_RETURN_TYPE ) {
2257
- int check = _check_inherited_return_type (
2256
+ inheritance_status status = check_inherited_return_type (
2258
2257
child , & child -> common .arg_info [-1 ],
2259
2258
parent , & parent -> common .arg_info [-1 ]);
2260
- if (check < 0 ) {
2261
- _inheritance_runtime_error_msg (child , parent );
2259
+ /* TODO I don't think this is right -- what if the class now exists
2260
+ * but has wrong variance? */
2261
+ if (status == INHERITANCE_UNRESOLVED ) {
2262
+ inheritance_runtime_error_msg (child , parent );
2262
2263
continue ;
2263
2264
}
2264
2265
} else {
@@ -2291,12 +2292,11 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce)
2291
2292
? & parent -> common .arg_info [i ]
2292
2293
: & parent -> common .arg_info [parent -> common .num_args ];
2293
2294
2294
- int check = _check_inherited_parameter_type (
2295
+ inheritance_status status = check_inherited_parameter_type (
2295
2296
child , child_arg_info ,
2296
2297
parent , parent_arg_info );
2297
-
2298
- if (check < 0 ) {
2299
- _inheritance_runtime_error_msg (child , parent );
2298
+ if (status == INHERITANCE_UNRESOLVED ) {
2299
+ inheritance_runtime_error_msg (child , parent );
2300
2300
continue ;
2301
2301
}
2302
2302
}
0 commit comments