File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -312,17 +312,21 @@ static inline bool can_elide_return_type_check(
312
312
313
313
if (disallowed_types == MAY_BE_OBJECT && use_info -> ce && ZEND_TYPE_IS_COMPLEX (arg_info -> type )) {
314
314
zend_type * single_type ;
315
+ /* For intersection: result==false is failure, default is success.
316
+ * For union: result==true is success, default is failure. */
317
+ bool is_intersection = ZEND_TYPE_IS_INTERSECTION (arg_info -> type );
315
318
ZEND_TYPE_FOREACH (arg_info -> type , single_type ) {
316
319
if (ZEND_TYPE_HAS_NAME (* single_type )) {
317
320
zend_string * lcname = zend_string_tolower (ZEND_TYPE_NAME (* single_type ));
318
321
zend_class_entry * ce = zend_optimizer_get_class_entry (script , lcname );
319
322
zend_string_release (lcname );
320
- if ( ce && ZEND_TYPE_IS_UNION ( arg_info -> type ) && safe_instanceof (use_info -> ce , ce )) {
321
- /* One of the class union types matched. */
322
- return true ;
323
+ bool result = ce && safe_instanceof (use_info -> ce , ce );
324
+ if ( result == ! is_intersection ) {
325
+ return result ;
323
326
}
324
327
}
325
328
} ZEND_TYPE_FOREACH_END ();
329
+ return is_intersection ;
326
330
}
327
331
328
332
return false;
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ function getClassUnion(): stdClass|FooBar {
51
51
return new stdClass ;
52
52
}
53
53
54
+ function getClassIntersection (): Traversable &Countable {
55
+ return new ArrayObject ;
56
+ }
57
+
54
58
?>
55
59
--EXPECTF--
56
60
$_main:
@@ -69,6 +73,16 @@ getClassUnion:
69
73
LIVE RANGES:
70
74
0: 0001 - 0002 (new)
71
75
76
+ getClassIntersection:
77
+ ; (lines=3, args=0, vars=0, tmps=1)
78
+ ; (after optimizer)
79
+ ; %s
80
+ 0000 V0 = NEW 0 string("ArrayObject")
81
+ 0001 DO_FCALL
82
+ 0002 RETURN V0
83
+ LIVE RANGES:
84
+ 0: 0001 - 0002 (new)
85
+
72
86
Test1::getIntOrFloat:
73
87
; (lines=2, args=1, vars=1, tmps=0)
74
88
; (after optimizer)
You can’t perform that action at this time.
0 commit comments