Skip to content

Regression: iterator_to_array() Generator via IIFE — closure param $g null TypeError (Zend/zend_closures.c) #16263

Description

@PurHur

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.phpinvokeClosure 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

  • maintainer_gap_iterator_to_array_generator.php prints ok on VM (IIFE + top-level)
  • Compliance .phpt guard under test/compliance/cases/language/ for Generator-through-IIFE
  • JIT/AOT agree when both backends lower the closure invoke path
  • php-src-strict; no php-compiler-strict shortcut

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions