Skip to content

Closure::bind does not co-own the new $this: it is freed with the last outside owner. #262

Closed

Description

@blacktrs

Summary

Closure::bind does not co-own the new $this: it is freed with the last outside owner.

Repro

<?php
class Box { private int $v = 42; }
function mk() { $read = function(): int { return $this->v; }; $o = new Box(); $b = Closure::bind($read, $o, Box::class); unset($o); return $b; }
$b = mk();
$x = [str_repeat("z", 64), str_repeat("y", 64)];
echo $b(), "\n";

Expected (php)

42

Actual (manticore 00b756b9, Darwin arm64)

0

Tracking

Known-bug repro: tests/aot/repro/wrong/closure_bind_this_not_owned.php — bash tests/aot/xfail.sh -k closure_bind_this_not_owned 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 15, 2026
  2. blacktrs commented on Oct 15, 2026

    @blacktrs
    ContributorAuthor

    On Linux arm64 (glibc, Docker) this repro reports XPASS: the freed Box block is not reused before the call, so the stale $this still reads 42. Red on macOS only; the bug (the rebind copy takes no count on the new $this when the source env has no retain function) is platform-independent.

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