Skip to content

A parent's method reaching a redeclared private through a receiver other than $this gets the subclass's slot. #577

Open

Description

@blacktrs

Summary

A parent's method reaching a redeclared private through a receiver other than $this gets the subclass's slot.

Repro

<?php
class P { private string $r = 'parent';
  public function viaParam(C $o): string { return $o->r; }
  public function viaErased($o): string { return $o->r; }
  public function viaNarrow(): string { return $this instanceof C ? $this->r : '?'; }
  public function viaBound(): string { return (function () { return $this->r; })->call($this); } }
class C extends P { private string $r = 'child'; }
$c = new C;
echo $c->viaParam($c), ' ', $c->viaErased($c), ' ', $c->viaNarrow(), ' ', $c->viaBound(), "\n";
$f = Closure::bind(function () { return $this->r; }, $c, P::class);
echo $f(), "\n";

Expected (php)

parent parent parent child
parent

Actual (manticore 0c6650f0, Darwin arm64)


[exit code 255]
PHP Fatal error:  Uncaught Error: Cannot access private property C::$r

Tracking

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

    @blacktrs
    ContributorAuthor

    Root cause found during the #655 sweep (not fixed, needs design): a private property slot must be resolved from the CALLING scope's private declaration, not from the receiver's static class. The repros need it on every path: the static typed path, the erased class-id switch helpers, $this instanceof C narrowing and Closure::bind scopes.

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