Skip to content

Commit 003c13d

Browse files
committed
Fix iterable return type optimization
1 parent 3e139a4 commit 003c13d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ static inline zend_bool can_elide_return_type_check(
302302
return 0;
303303
}
304304

305-
if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE) {
305+
/* These types are not represented exactly */
306+
if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE || ZEND_TYPE_CODE(info->type) == IS_ITERABLE) {
306307
return 0;
307308
}
308309

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Don't optimize object -> iterable
3+
--FILE--
4+
<?php
5+
6+
function test(object $arg): iterable {
7+
return $arg;
8+
}
9+
test(new stdClass);
10+
11+
?>
12+
--EXPECTF--
13+
Fatal error: Uncaught TypeError: Return value of test() must be iterable, object returned in %s:%d
14+
Stack trace:
15+
#0 %s(%d): test(Object(stdClass))
16+
#1 {main}
17+
thrown in %s on line %d

0 commit comments

Comments
 (0)