Skip to content

A private property or method accessed from inside a closure that is not bound to the class is not access-checked #422

Closed

Description

@blacktrs

Summary

A private property or method accessed from inside a closure that is not bound to the class is not access-checked.

Repro

<?php
class A { private int $x = 1; private function f() { return 2; } }
$g = function (A $o) {
    try { var_dump($o->x); } catch (Error $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }
    try { var_dump($o->f()); } catch (Error $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }
};
$g(new A);

Expected (php)

Error: Cannot access private property A::$x
Error: Call to private method A::f() from global scope

Actual (manticore 35461ba2, Darwin arm64)

int(1)
int(2)

Tracking

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