Skip to content

Stdlib: ParentIterator under RecursiveIteratorIterator yields nothing — Zend visits parent nodes (ext/spl/spl_iterators.c) #22007

Closed

Description

@PurHur

Category

bug · php-src-strict · SPL ParentIterator + RII

Problem

ParentIterator alone correctly skips non-parent elements (manual rewind/valid/next matches Zend). Wrapping it in RecursiveIteratorIterator (SELF_FIRST or CHILD_FIRST) yields zero iterations on the VM, while Zend visits each parent node once.

Repro Zend 8.2+ VM (2026-07-22, 1db3a39)
foreach (new RecursiveIteratorIterator(new ParentIterator(new RecursiveArrayIterator([1,[2,3],4])), RecursiveIteratorIterator::SELF_FIRST) as $k=>$v) one item: key 1, is_array($v)===true count=0

Related closed work (#19784 instanceof, #13211 rewind) does not cover this RII nesting gap.

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '\''
$n=0;
foreach (new RecursiveIteratorIterator(
  new ParentIterator(new RecursiveArrayIterator([1,[2,3],4])),
  RecursiveIteratorIterator::SELF_FIRST
) as $k=>$v) { $n++; echo "k=$k arr=".(is_array($v)?"1":"0")."\n"; }
echo "count=$n\n";
'\'''

Expect Zend: count=1. VM today: count=0.

Done when

  • RII + ParentIterator SELF_FIRST / CHILD_FIRST match Zend visit order and count on nested RecursiveArrayIterator
  • Manual ParentIterator iteration remains green
  • Compliance .phpt under test/compliance/cases/spl/
  • 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 Jul 22, 2026
  2. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #21977, #21994, #22007)

    Working #21977 first (SplMinHeap/SplMaxHeap subclass compare). Then #21994, then #22007. Separate PRs; merge each before the next.

  3. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    Merged in #22013

    Root cause: sibling positional New_ matching mapped nested ParentIterator/RecursiveArrayIterator onto the wrong RII ctor args (mode / iterator).

    Verification: VM+JIT repro count=1; phpunit filter OK (8).

    Batch (#21977, #21994, #22007) complete.

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