Skip to content

A by-value array $a param appended in the callee: crash / raw pointer / caller's array mutated #27

Closed

Description

@blacktrs

Summary

A by-value array $a param appended in the callee: crash / raw pointer / caller's array mutated.

Repro

<?php
function g(array $a): int { $a[] = 1; return count($a); }
function h(array $a): void { $a[] = 1; echo json_encode($a), "\n"; }
echo g(['a', 'b']), "\n";
h(['k' => 'v']);
$f = function (array $a): int { $a[] = 9; return count($a); };
$x = [1, 2];
$f($x);
echo json_encode($x), "\n";

Expected (php 8.5)

3
{"k":"v","0":1}
[1,2]

Actual (manticore 10affa68, macOS arm64)

3
{"k":4300121208,"0":1}
[1,2]

Tracking

Known-bug repro: tests/aot/repro/wrong/array_param_append.php — bash tests/aot/xfail.sh -k array_param_append 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. added
    needs-design
    area:types
    area:refs
    on Oct 13, 2026
  3. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Scope: needs the parked element-repr epic. function h(array $a){ $a[]=1; } called with an assoc string array: the callee's base is erased (unknown) and the stored value is a raw int, so the store stamps the buffer's element hint as INT without converting the existing string pointers. The proper fix is a boxed store into erased bases (Ownership::storeElemBoxesValue for KIND_UNKNOWN). That function's comment and the red case tests/aot/cases/array_erased_elem_repr_gap.php record why it is not done: the repr nibble is fixed at allocation, boxed values in a raw-repr buffer get freed as tagged words, and gen-2 segfaulted on its own smoke test. The g(array) and closure parts of the repro already pass. Found in batch D; 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:refsarea:typesbugneeds-designwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions