Skip to content

foreach over an ArrayObject iterates a snapshot: elements appended inside the loop are never visited. #300

Closed

Description

@blacktrs

Summary

foreach over an ArrayObject iterates a snapshot: elements appended inside the loop are never visited.

Repro

<?php
$ao = new ArrayObject([1, 2, 3]);
foreach ($ao as $k => $v) { if ($k < 5) { $ao[] = 0; } }
echo count($ao), "\n";
$n = 0;
foreach ($ao as $v) { $n++; }
echo $n, "\n";

Expected (php)

8
8

Actual (manticore aef791af, Darwin arm64)

6
6

Tracking

Known-bug repro: tests/aot/repro/wrong/arrayobject_foreach_snapshot.php — bash tests/aot/xfail.sh -k arrayobject_foreach_snapshot reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 17, 2026
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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions