Skip to content

array_walk_recursive on a by-value array param mutates the caller's array #178

Closed

Description

@blacktrs

Summary

array_walk_recursive on a by-value array param mutates the caller's array.

Repro

<?php
class C { public function f(array $a) { array_walk_recursive($a, static function (&$item) { $item = 'S'; }); return $a; } }
$d = ['a' => 'x', 'c' => ['e' => 'f']];
(new C)->f($d);
echo json_encode($d), "\n";

Expected (php)

{"a":"x","c":{"e":"f"}}

Actual (manticore f6498c48, Darwin arm64)

{"a":"S","c":{"e":"S"}}

Tracking

Known-bug repro: tests/aot/repro/wrong/array_walk_recursive_mutates_caller_array.php — bash tests/aot/xfail.sh -k array_walk_recursive_mutates_caller_array reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

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