Skip to content

by-ref foreach storing a fresh object per element: both elements report object id #1 (php #3 and #1) #72

Open

Description

@blacktrs

Summary

by-ref foreach storing a fresh object per element: both elements report object id #1 (php #3 and #1).

Repro

<?php
// item: 19
class O {}
$a = [new O, new O];
foreach ($a as &$v) { $v = new stdClass; }
unset($v);
var_dump($a);

Expected (php)

array(2) {
  [0]=>
  object(stdClass)#3 (0) {
  }
  [1]=>
  object(stdClass)#1 (0) {
  }
}

Actual (manticore 09cb49fb, Darwin arm64)

array(2) {
  [0]=>
  object(stdClass)#1 (0) {
  }
  [1]=>
  object(stdClass)#1 (0) {
  }
}

Tracking

Known-bug repro: tests/aot/repro/wrong/foreach_byref_object_ids.php — bash tests/aot/xfail.sh -k foreach_byref_object_ids 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 5, 2026
  2. blacktrs commented on Oct 6, 2026

    @blacktrs
    ContributorAuthor

    Root cause, seen while working on #101: the object id is not computed at all — LowerPrelude::dumpObjectSrc emits the literal #1 in every var_dump object arm (object(Foo)#1 (…)), including the __debugInfo and stdClass arms. So this is not specific to by-ref foreach: $a = new P; $b = new P; var_dump($a, $b); prints #1 twice (php: #1, #2), while spl_object_id() answers correctly.

  3. added
    needs-design
    area:runtime
    on Oct 13, 2026
  4. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Scope: object handle ids. var_dump hardcodes #1; there are no real object handle ids and no free-list reuse, so #3 / #1 cannot match php. Fix: allocate a handle id per object (with a free list on destruct) and print it in var_dump/spl_object_id. Found in batch E; skipped.

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:runtimebugneeds-designwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions