Skip to content

A write to $this->a from a child class scope creates a dynamic property when the parent's $a is private; the binary overwrites the parent's private. #475

Open

Description

@blacktrs

Summary

A write to $this->a from a child class scope creates a dynamic property when the parent's $a is private; the binary overwrites the parent's private.

Repro

<?php
class Base { private $a = 'parent-private'; public function pa() { return $this->a; } }
#[AllowDynamicProperties]
class Child extends Base {}
function hydrate(object $o): void
{
    $set = Closure::bind(function (): void { $this->a = 'x'; }, $o, get_class($o));
    $set();
}
$c = new Child();
hydrate($c);
echo $c->pa(), "\n";
print_r($c);

Expected (php)

parent-private
Child Object
(
    [a:Base:private] => parent-private
    [a] => x
)

Actual (manticore 7599a57b, Darwin arm64)

x
Child Object
(
    [a:Base:private] => x
)

Tracking

Known-bug repro: tests/aot/repro/wrong/parent_private_write_from_child_scope.php — bash tests/aot/xfail.sh -k parent_private_write_from_child_scope 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 25, 2026
  2. added
    needs-design
    on Oct 30, 2026
  3. 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

    bugneeds-designwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions