Skip to content

Regression: CachingIterator multi TOSTRING flags accepted — Zend ValueError exclusive bits (ext/spl/spl_iterators.c) #31551

Description

@PurHur

Category

Regression: · php-src-strict · CachingIterator mutually exclusive TOSTRING flags

Problem

Zend rejects combinations of more than one of CALL_TOSTRING / TOSTRING_USE_KEY / TOSTRING_USE_CURRENT / TOSTRING_USE_INNER with ValueError on both __construct and setFlags. VM accepts the multi-bit mask silently (construct + setFlags succeed).

Sibling history: #24252 (setFlags clearing CALL_TOSTRING), #22336 (default/null flags) — neither covers the exclusive-OR ValueError gate.

Probed 2026-08-16 — host Zend PHP 8.2.32 vs php bin/vm.php.

Repro Zend 8.2+ VM (2026-08-16)
new CachingIterator($it, CALL_TOSTRING|TOSTRING_USE_KEY) ValueError: CachingIterator::__construct(): Argument #2 ($flags) must contain only one of … construct succeeds
$c->setFlags(CALL_TOSTRING|TOSTRING_USE_KEY) ValueError: CachingIterator::setFlags(): Argument #1 ($flags) must contain only one of … setFlags succeeds

php-src reference

PHP implementation target

  • ext/spl/CachingIteratorBuiltin.php — shared flag validator used by construct + setFlags (and RecursiveCachingIterator if it shares the path)
  • PHP-in-PHP; no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_cachingiterator_multi_tostring_flags.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_cachingiterator_multi_tostring_flags.php'

Done when

  • Construct + setFlags with two TOSTRING bits throw Zend-shaped ValueError messages
  • Single-bit and FULL_CACHE combinations still match Zend
  • Targeted compliance/PHPUnit guard
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 16, 2026
  2. PurHur commented on Aug 16, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-A — starting this run (language queue empty; lane A behavioral SPL IR)

  3. PurHur commented on Aug 16, 2026

    @PurHur
    OwnerAuthor

    Merged #31564

    Verification

    • Repro Zend vs php bin/vm.php test/repro/maintainer_gap_cachingiterator_multi_tostring_flags.php — byte-identical ValueError on construct + setFlags
    • ./script/phpunit.sh --filter 'Issue31551CachingIteratorMultiToStringFlagsTest|CachingIteratorMultiToStringFlags31551VMTest' — OK (2 tests)
    • Sibling CachingIterator flag phpt still match on VM

    php-src-strict: ext/spl/CachingIteratorBuiltin.php assertExclusiveToStringFlags (also RecursiveCachingIterator construct).

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: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