Skip to content

Regression: iterator_to_array(..., null) $preserve_keys under strict_types succeeds — Zend TypeError (ext/spl/iterator.c) #31340

Description

@PurHur

Category

stdlib · php-src-strict

Problem

Under declare(strict_types=1), iterator_to_array($iterator, null) must TypeError because $preserve_keys is typed bool. VM coerces null via toBool()false-ish success and returns the array (keys preserved as default path effectively treats null as false/toBool).

Repro Zend 8.2.32 (2026-08-15) VM (2026-08-15)
iterator_to_array(new ArrayIterator([1, 2]), null) TypeError: … Argument #2 ($preserve_keys) must be of type bool, null given array(0 => 1, 1 => 2)

Note: null iterator TypeError is already covered (#21893 closed). This issue is only the $preserve_keys bool param.

php-src reference

PHP implementation target

  • ext/standard/iterator_to_array.php — replace $frame->calledArgs[1]->resolveIndirect()->toBool() with VmMath::parseBoolBuiltinArgForFrame
  • JIT: JitBoolArg::lower / compileTimePreserveKeys path must TypeError on null under strict (not coerce)
  • No new C runtime logic

Repro

./script/docker-exec.sh -- bash -lc 'php -r '\''declare(strict_types=1); try { iterator_to_array(new ArrayIterator([1, 2]), null); } catch (Throwable $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; }'\'''
./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '\''declare(strict_types=1); try { var_export(iterator_to_array(new ArrayIterator([1, 2]), null)); echo "\n"; } catch (Throwable $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; }'\'''

Done when

  • VM/JIT/AOT: null $preserve_keys under strict_types → Zend TypeError; omit-arg still defaults true
  • Compliance .phpt under test/compliance/cases/stdlib/
  • php-src-strict; no php-compiler-strict shortcut

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions