@@ -225,7 +225,7 @@ static zend_always_inline void register_unresolved_class(zend_string *name) {
225
225
zend_hash_add_empty_element (CG (delayed_autoloads ), name );
226
226
}
227
227
228
- static zend_class_entry * lookup_class (
228
+ static zend_class_entry * lookup_class_ex (
229
229
zend_class_entry * scope , zend_string * name , bool register_unresolved ) {
230
230
zend_class_entry * ce ;
231
231
@@ -270,6 +270,10 @@ static zend_class_entry *lookup_class(
270
270
return NULL ;
271
271
}
272
272
273
+ static zend_class_entry * lookup_class (zend_class_entry * scope , zend_string * name ) {
274
+ return lookup_class_ex (scope , name , /* register_unresolved */ false);
275
+ }
276
+
273
277
/* Instanceof that's safe to use on unlinked classes. */
274
278
static bool unlinked_instanceof (zend_class_entry * ce1 , zend_class_entry * ce2 ) {
275
279
if (ce1 == ce2 ) {
@@ -350,7 +354,7 @@ static bool zend_type_permits_self(
350
354
ZEND_TYPE_FOREACH (type , single_type ) {
351
355
if (ZEND_TYPE_HAS_NAME (* single_type )) {
352
356
zend_string * name = resolve_class_name (scope , ZEND_TYPE_NAME (* single_type ));
353
- zend_class_entry * ce = lookup_class (self , name , /* register_unresolved */ 0 );
357
+ zend_class_entry * ce = lookup_class (self , name );
354
358
if (ce && unlinked_instanceof (self , ce )) {
355
359
return 1 ;
356
360
}
@@ -401,14 +405,13 @@ static void track_class_dependency(zend_class_entry *ce, zend_string *class_name
401
405
402
406
static inheritance_status zend_perform_covariant_class_type_check (
403
407
zend_class_entry * fe_scope , zend_string * fe_class_name , zend_class_entry * fe_ce ,
404
- zend_class_entry * proto_scope , zend_type proto_type ,
405
- bool register_unresolved ) {
408
+ zend_class_entry * proto_scope , zend_type proto_type ) {
406
409
bool have_unresolved = 0 ;
407
410
if (ZEND_TYPE_FULL_MASK (proto_type ) & MAY_BE_OBJECT ) {
408
411
/* Currently, any class name would be allowed here. We still perform a class lookup
409
412
* for forward-compatibility reasons, as we may have named types in the future that
410
413
* are not classes (such as enums or typedefs). */
411
- if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name , register_unresolved );
414
+ if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name );
412
415
if (!fe_ce ) {
413
416
have_unresolved = 1 ;
414
417
} else {
@@ -417,7 +420,7 @@ static inheritance_status zend_perform_covariant_class_type_check(
417
420
}
418
421
}
419
422
if (ZEND_TYPE_FULL_MASK (proto_type ) & MAY_BE_ITERABLE ) {
420
- if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name , register_unresolved );
423
+ if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name );
421
424
if (!fe_ce ) {
422
425
have_unresolved = 1 ;
423
426
} else if (unlinked_instanceof (fe_ce , zend_ce_traversable )) {
@@ -437,11 +440,10 @@ static inheritance_status zend_perform_covariant_class_type_check(
437
440
return INHERITANCE_SUCCESS ;
438
441
}
439
442
440
- if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name , register_unresolved );
441
- proto_ce =
442
- lookup_class (proto_scope , proto_class_name , register_unresolved );
443
+ if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name );
444
+ proto_ce = lookup_class (proto_scope , proto_class_name );
443
445
} else if (ZEND_TYPE_HAS_CE (* single_type )) {
444
- if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name , register_unresolved );
446
+ if (!fe_ce ) fe_ce = lookup_class (fe_scope , fe_class_name );
445
447
proto_ce = ZEND_TYPE_CE (* single_type );
446
448
} else {
447
449
continue ;
@@ -459,6 +461,16 @@ static inheritance_status zend_perform_covariant_class_type_check(
459
461
return have_unresolved ? INHERITANCE_UNRESOLVED : INHERITANCE_ERROR ;
460
462
}
461
463
464
+ static void register_unresolved_classes (zend_class_entry * scope , zend_type type ) {
465
+ zend_type * single_type ;
466
+ ZEND_TYPE_FOREACH (type , single_type ) {
467
+ if (ZEND_TYPE_HAS_NAME (* single_type )) {
468
+ zend_string * class_name = resolve_class_name (scope , ZEND_TYPE_NAME (* single_type ));
469
+ lookup_class_ex (scope , class_name , /* register_unresolved */ true);
470
+ }
471
+ } ZEND_TYPE_FOREACH_END ();
472
+ }
473
+
462
474
static inheritance_status zend_perform_covariant_type_check (
463
475
zend_class_entry * fe_scope , zend_type fe_type ,
464
476
zend_class_entry * proto_scope , zend_type proto_type )
@@ -516,13 +528,11 @@ static inheritance_status zend_perform_covariant_type_check(
516
528
zend_string * fe_class_name =
517
529
resolve_class_name (fe_scope , ZEND_TYPE_NAME (* single_type ));
518
530
status = zend_perform_covariant_class_type_check (
519
- fe_scope , fe_class_name , NULL ,
520
- proto_scope , proto_type , /* register_unresolved */ 0 );
531
+ fe_scope , fe_class_name , NULL , proto_scope , proto_type );
521
532
} else if (ZEND_TYPE_HAS_CE (* single_type )) {
522
533
zend_class_entry * fe_ce = ZEND_TYPE_CE (* single_type );
523
534
status = zend_perform_covariant_class_type_check (
524
- fe_scope , fe_ce -> name , fe_ce ,
525
- proto_scope , proto_type , /* register_unresolved */ 0 );
535
+ fe_scope , fe_ce -> name , fe_ce , proto_scope , proto_type );
526
536
} else {
527
537
continue ;
528
538
}
@@ -540,21 +550,8 @@ static inheritance_status zend_perform_covariant_type_check(
540
550
return INHERITANCE_SUCCESS ;
541
551
}
542
552
543
- /* Register all classes that may have to be resolved */
544
- ZEND_TYPE_FOREACH (fe_type , single_type ) {
545
- if (ZEND_TYPE_HAS_NAME (* single_type )) {
546
- zend_string * fe_class_name =
547
- resolve_class_name (fe_scope , ZEND_TYPE_NAME (* single_type ));
548
- zend_perform_covariant_class_type_check (
549
- fe_scope , fe_class_name , NULL ,
550
- proto_scope , proto_type , /* register_unresolved */ 1 );
551
- } else if (ZEND_TYPE_HAS_CE (* single_type )) {
552
- zend_class_entry * fe_ce = ZEND_TYPE_CE (* single_type );
553
- zend_perform_covariant_class_type_check (
554
- fe_scope , fe_ce -> name , fe_ce ,
555
- proto_scope , proto_type , /* register_unresolved */ 1 );
556
- }
557
- } ZEND_TYPE_FOREACH_END ();
553
+ register_unresolved_classes (fe_scope , fe_type );
554
+ register_unresolved_classes (proto_scope , proto_type );
558
555
return INHERITANCE_UNRESOLVED ;
559
556
}
560
557
0 commit comments