Skip to content

Stdlib: iterator_to_array(null) always TypeError (#21893) - #21909

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-21893-iterator-to-array-null-typeerror
Jul 21, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/stdlib-21893-iterator-to-array-null-typeerror

Conversation

@PurHur

@PurHur PurHur commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

php-src: ext/spl/spl.stub.php, ext/spl/iterator.c — PHP_FUNCTION(iterator_to_array).
PHP impl: ext/standard/iterator_to_array.php (VM via VM::iteratorToArray → VmIteratorWalk::assertTraversable; JIT null via JitIterableArg::emitIterableTypeErrorAndAbort).

Closes #21893

Test plan

  • VM repro matches Zend
  • JIT repro matches Zend
  • PHPUnit filter iterator_to_array_null_typeerror|array_null_soft_forward84
  • Bare AOT iterator_to_array(null) compiles and hits TypeError abort path (same as iterator_count(null) AOT)
  • Catchable AOT try/catch for abort-based TypeError — known shared limitation (not new to this PR)

Verification

php bin/vm.php test/repro/issue_21893_iterator_to_array_null_typeerror.php
# TypeError: iterator_to_array(): Argument #1 ($iterator) must be of type Traversable|array, null given

php bin/jit.php test/repro/issue_21893_iterator_to_array_null_typeerror.php
# same

php -d memory_limit=1536M vendor/bin/phpunit --filter 'iterator_to_array_null_typeerror|array_null_soft_forward84'
# OK (8 tests)

printf '%s\n' '<?php' 'iterator_to_array(null);' > /tmp/ita_bare.php
php bin/compile.php -o /tmp/ita_bare /tmp/ita_bare.php && /tmp/ita_bare
# exit 134 (TypeError abort; matches iterator_count AOT)

php script/bootstrap-inventory.php --check
# OK 6326/6326

Pillar 1 note (pre-existing)

make bootstrap-selfhost-link red on this host: SuperglobalRefreshJitHelper::buildGetTable() TypeError (#21888 / open PR #21904) — unrelated to this stdlib change.

Made with Cursor

Typed Traversable|array rejects null without InternalStrictArg / soft-empty
coercion (php-src ext/spl). Drop iterator_to_array from the #21771 soft-null
batch; guard with compliance + repro (VM/JIT).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit de7b5b8 into master Jul 21, 2026
1 check failed
@PurHur
PurHur deleted the agent/stdlib-21893-iterator-to-array-null-typeerror branch July 21, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: iterator_to_array(null) returns [] — Zend TypeError (ext/spl/iterator.c)

1 participant