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
Category
stdlib· php-src-strictProblem
Under
declare(strict_types=1),iterator_to_array($iterator, null)mustTypeErrorbecause$preserve_keysis typedbool. VM coercesnullviatoBool()→false-ish success and returns the array (keys preserved as default path effectively treats null as false/toBool).iterator_to_array(new ArrayIterator([1, 2]), null)TypeError: … Argument #2 ($preserve_keys) must be of type bool, null givenarray(0 => 1, 1 => 2)Note: null iterator TypeError is already covered (#21893 closed). This issue is only the
$preserve_keysbool param.php-src reference
ext/spl/iterator.c—PHP_FUNCTION(iterator_to_array)(Z_PARAM_BOOLpreserve_keys)ext/spl/spl.stub.php—iterator_to_array(Traversable|array $iterator, bool $preserve_keys = true): arrayPHP implementation target
ext/standard/iterator_to_array.php— replace$frame->calledArgs[1]->resolveIndirect()->toBool()withVmMath::parseBoolBuiltinArgForFrameJitBoolArg::lower/compileTimePreserveKeyspath must TypeError on null under strict (not coerce)Repro
Done when
$preserve_keysunder strict_types → ZendTypeError; omit-arg still defaults true.phptundertest/compliance/cases/stdlib/