Skip to content

foreach by reference over a SplFixedArray iterates instead of throwing "An iterator cannot be used with foreach by reference" #163

Closed

Description

@blacktrs

Summary

foreach by reference over a SplFixedArray iterates instead of throwing "An iterator cannot be used with foreach by reference".

Repro

<?php
$a = new SplFixedArray(2);
$a[0] = 1; $a[1] = 2;
try {
    foreach ($a as &$r) { echo "iterated\n"; }
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

Expected (php)

Error: An iterator cannot be used with foreach by reference

Actual (manticore 8ef0d6a2, Darwin arm64)

iterated
iterated

Tracking

Known-bug repro: tests/aot/repro/wrong/splfixedarray_foreach_byref_iterates.php — bash tests/aot/xfail.sh -k splfixedarray_foreach_byref_iterates 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 9, 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