Category
stdlib
Status (refreshed 2026-06-02 — backlog-architect)
Phase 1 landed: iterator_to_array() is registered in ext/standard/Module.php. VM handles arrays and Generators via VM::iteratorToArray(); JIT handles compile-time Generator args via JitIteratorToArray.
Remaining gap (phase 2 → #4244): Iterator / IteratorAggregate objects still throw LogicException — see lib/VM.php:705-707.
| Piece |
Status |
| Builtin registered |
✅ |
| VM: array input |
✅ |
| VM: Generator input |
✅ |
| VM: Iterator/IteratorAggregate |
❌ → #4244 |
JIT: runtime $preserve_keys |
❌ (compile-time bool only) |
| JIT: Iterator objects |
❌ |
Problem (original)
Zend iterator_to_array(Traversable $iterator, bool $preserve_keys = false) materializes any traversable into an array. Frameworks use it for generator→array conversion and SPL iterators.
php-src reference
Repro — Generator (passes today)
<?php
$g = (function () { yield 1; yield 2; })();
var_export(iterator_to_array($g));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
\$g = (function () { yield 1; yield 2; })();
var_export(iterator_to_array(\$g));
"'
| Engine |
Result |
| Zend PHP 8.3+ |
array ( 0 => 1, 1 => 2, ) |
| This compiler VM |
✅ same (after phase 1) |
Repro — Iterator object (still fails → #4244)
<?php
class OneShot implements Iterator {
private bool $done = false;
public function rewind(): void { $this->done = false; }
public function valid(): bool { return !$this->done; }
public function current(): int { return 42; }
public function key(): int { return 0; }
public function next(): void { $this->done = true; }
}
var_export(iterator_to_array(new OneShot()));
Actual: LogicException: iterator_to_array() argument must be an array or Generator
Scope (close this issue when)
Done when (this issue)
Related
Category
stdlibStatus (refreshed 2026-06-02 — backlog-architect)
Phase 1 landed:
iterator_to_array()is registered inext/standard/Module.php. VM handles arrays and Generators viaVM::iteratorToArray(); JIT handles compile-time Generator args viaJitIteratorToArray.Remaining gap (phase 2 → #4244):
Iterator/IteratorAggregateobjects still throwLogicException— seelib/VM.php:705-707.$preserve_keysProblem (original)
Zend
iterator_to_array(Traversable $iterator, bool $preserve_keys = false)materializes any traversable into an array. Frameworks use it for generator→array conversion and SPL iterators.php-src reference
ext/spl/iterator.c—PHP_FUNCTION(iterator_to_array)Zend/zend_interfaces.c—zend_iterator_to_array()Repro — Generator (passes today)
array ( 0 => 1, 1 => 2, )Repro — Iterator object (still fails → #4244)
Actual:
LogicException: iterator_to_array() argument must be an array or GeneratorScope (close this issue when)
ext/standard/iterator_to_array.php,lib/VM.php)test/compliance/cases/stdlib/iterator_to_array_generator.phptor equivalent)$preserve_keys(optional follow-up)Done when (this issue)
Related