Skip to content

A local read at the top of a loop body reads its reference box's address once a later $x = &$a[$k] in the same body has rebound it #642

Open

Description

@blacktrs

Summary

A local passed to a function called by run-time name reads as a raw box address once a later $x = &$a[$k] in the loop has rebound it.

Repro

<?php
function show(mixed $v): string { return var_export($v, true); }
function run(string $n, array $a): void {
    $x = 10;
    foreach ([0, 1] as $k) {
        echo $n($x), "\n";
        $x = &$a[$k];
    }
    $x = 99;
    echo json_encode($a), "\n";
}
run($argc > 9 ? '' : 'show', [1, 2]);

Expected (php)

10
1
[1,99]

Actual (manticore cb38861b, Darwin arm64)

10
2.44429725E-314
[1,99]

Tracking

Known-bug repro: tests/aot/repro/wrong/dyn_name_call_local_later_ref_bound.php — bash tests/aot/xfail.sh -k dyn_name_call_local_later_ref_bound 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 Nov 10, 2026
  2. changed the title [-]A local passed to a function called by run-time name reads as a raw box address once a later `$x = &$a[$k]` in the loop has rebound it.[/-] [+]A local read at the top of a loop body reads its reference box's address once a later $x = &$a[$k] in the same body has rebound it[/+] on Nov 10, 2026
  3. blacktrs commented on Nov 10, 2026

    @blacktrs
    ContributorAuthor

    Narrowed: not specific to by-name calls. A direct show($x) at the top of the loop body misreads the same way (2.2E-314 instead of 1 on the second iteration), as does call_user_func. The repro is now the direct form: tests/aot/repro/wrong/local_read_before_later_ref_bind.php. Reproduces on v0.18.0.

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