Category
Language · php-src-strict · closure invoke / Generator forwarding
Problem
Passing a Generator from a generator-expression closure into an immediately-invoked closure loses the argument on the VM. Zend materializes [1, 2] from both the IIFE path and the top-level call.
| Repro |
Zend 8.2 (Docker) |
VM (2026-07-05) |
(function (Generator $g) { return iterator_to_array($g); })($gen()) |
ok |
Undefined variable $g + TypeError: iterator_to_array(): Argument #1 must be Traversable|array, null given |
iterator_to_array($gen()) (top-level) |
ok |
ok |
php-src reference
PHP implementation target
lib/Compiler.php — IIFE / call-site argument wiring for typed closure parameters
ext/standard/VmClosureCall.php — ensure Generator objects copy/forward into invokeClosure
lib/VM.php — invokeClosure arity binding when callee is a named closure expression
Repro
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_iterator_to_array_generator.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_iterator_to_array_generator.php'
Done when
Category
Language· php-src-strict · closure invoke / Generator forwardingProblem
Passing a
Generatorfrom a generator-expression closure into an immediately-invoked closure loses the argument on the VM. Zend materializes[1, 2]from both the IIFE path and the top-level call.(function (Generator $g) { return iterator_to_array($g); })($gen())okUndefined variable $g+TypeError: iterator_to_array(): Argument #1 must be Traversable|array, null giveniterator_to_array($gen())(top-level)okokphp-src reference
Zend/zend_closures.c—zend_invoke_closure_callableext/standard/array.c—PHP_FUNCTION(iterator_to_array)PHP implementation target
lib/Compiler.php— IIFE / call-site argument wiring for typed closure parametersext/standard/VmClosureCall.php— ensure Generator objects copy/forward intoinvokeClosurelib/VM.php—invokeClosurearity binding when callee is a named closure expressionRepro
Done when
maintainer_gap_iterator_to_array_generator.phpprintsokon VM (IIFE + top-level).phptguard undertest/compliance/cases/language/for Generator-through-IIFE