Skip to content

$o[$i] on an ArrayAccess object returned through a mixed function keeps an extra reference: the element's destructor runs at shutdown #100

Closed

Description

@blacktrs

Summary

$o[$i] on an ArrayAccess object returned through a mixed function keeps an extra reference: the element's destructor runs at shutdown.

Repro

<?php
class Tok { public function __destruct() { echo "tok\n"; } }
class Box implements ArrayAccess {
    /** @var array<int, mixed> */
    private array $d = [];
    public function offsetExists(mixed $o): bool { return isset($this->d[$o]); }
    public function offsetGet(mixed $o): mixed { return $this->d[$o]; }
    public function offsetSet(mixed $o, mixed $v): void { $this->d[$o] = $v; }
    public function offsetUnset(mixed $o): void { unset($this->d[$o]); }
}
function first(Box $b): mixed { return $b[0]; }
$b = new Box(); $b[0] = new Tok();
$x = first($b);
unset($x);
unset($b);
echo "end\n";

Expected (php)

tok
end

Actual (manticore a35f8aa0, Darwin arm64)

end
tok

Tracking

Known-bug repro: tests/aot/repro/wrong/arrayaccess_read_owned_result_leaks.php — bash tests/aot/xfail.sh -k arrayaccess_read_owned_result_leaks 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
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