Skip to content

array_shift / array_pop on an element ($a['q']) mutate the inner array in place, so a copy of the outer array and a reused literal change too #601

Closed

Description

@blacktrs

Summary

array_shift / array_pop on an element ($a['q']) mutate the inner array in place, so a copy of the outer array and a reused literal change too.

Repro

<?php
function mk(int $n): array { return ['q' => range(1, $n)]; }
$a = mk(3);
$b = $a;
array_shift($a['q']);
array_pop($a['q']);
echo json_encode($a), ' ', json_encode($b), "\n";
for ($i = 0; $i < 3; $i++) { $el = ['q' => [1, 2, 3]]; echo array_shift($el['q']), ' '; }
echo "\n";

Expected (php)

{"q":[2]} {"q":[1,2,3]}
1 1 1 

Actual (manticore a9c79b1c, Darwin arm64)

{"q":[2]} {"q":[2]}
1 2 3 

Tracking

Known-bug repro: tests/aot/repro/wrong/array_mutator_on_element_corrupts_copy.php — bash tests/aot/xfail.sh -k array_mutator_on_element_corrupts_copy 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
    bugSomething isn't working
    wrong-answerCompiles and runs, output differs from php
    on Nov 9, 2026
  2. added a commit that references this issue on Nov 9, 2026
    6600c0f
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

    bugSomething isn't workingwrong-answerCompiles and runs, output differs from php

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions