diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index 4204f538051..5401c9df6a7 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -321,7 +321,8 @@ static inline zend_bool can_elide_return_type_check( return 0; } - if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE) { + /* These types are not represented exactly */ + if (ZEND_TYPE_CODE(info->type) == IS_CALLABLE || ZEND_TYPE_CODE(info->type) == IS_ITERABLE) { return 0; } diff --git a/ext/opcache/tests/iterable_type_optimization.phpt b/ext/opcache/tests/iterable_type_optimization.phpt new file mode 100644 index 00000000000..b5247cd69c0 --- /dev/null +++ b/ext/opcache/tests/iterable_type_optimization.phpt @@ -0,0 +1,17 @@ +--TEST-- +Don't optimize object -> iterable +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught TypeError: Return value of test() must be iterable, object returned in %s:%d +Stack trace: +#0 %s(%d): test(Object(stdClass)) +#1 {main} + thrown in %s on line %d