Skip to content

Stdlib: iterator_to_array(null $preserve_keys) TypeError under strict_types (#31340) - #31376

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-31340-iterator-to-array-preserve-keys-null
Aug 16, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-31340-iterator-to-array-preserve-keys-null

Conversation

@PurHur

@PurHur PurHur commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix iterator_to_array(..., null) $preserve_keys under declare(strict_types=1) to match Zend/php-src Z_PARAM_BOOL (TypeError instead of coercing via toBool()).
  • Soft-null (non-strict) emits E_DEPRECATED and coerces to false via shared parseBoolBuiltinArgForFrame / JitBoolArg::lowerCoerceZParamBool.
  • Omit-arg still defaults preserve_keys=true.

Closes #31340

php-src: ext/spl/iterator.c / ext/spl/spl.stub.php

Test plan

  • ./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/issue_31340_iterator_to_array_null_preserve_keys.php'
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/repro/…'
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/compile.php -o /tmp/ita31340 test/repro/… && /tmp/ita31340'
  • ./script/phpunit.sh --filter IteratorToArrayNullPreserveKeysStrict31340 (VM + JIT + soft DEP)
  • ./script/phpunit.sh --filter iterator_to_array_null_preserve_keys_strict --group aot

Verification transcript

TypeError: iterator_to_array(): Argument #2 ($preserve_keys) must be of type bool, null given
OK (3 tests, 3 assertions)  # dedicated VM/JIT provider
OK (1 test, 5 assertions)    # AOT group filter

Made with Cursor

…_types (#31340)

Route Z_PARAM_BOOL $preserve_keys through parseBoolBuiltinArgForFrame /
lowerCoerceZParamBool so caller strict_types TypeErrors match Zend; soft-null
keeps DEP+coerce to false. AOT early-return after compile-time null abort.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 3714a7a into master Aug 16, 2026
1 check failed
@PurHur
PurHur deleted the agent/issue-31340-iterator-to-array-preserve-keys-null branch August 16, 2026 09:17
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) $preserve_keys under strict_types succeeds — Zend TypeError (ext/spl/iterator.c)

1 participant