Skip to content

AOT: inherited property defaults are not initialised — every subclass loses its parent's defaults #31895

Description

@PurHur

What

Under AOT, a property default declared on a parent class is not applied when a subclass is instantiated. Instantiating the parent directly works, so this is specific to inheritance.

Both typed and untyped properties are affected. The untyped case degrades to a warning plus empty output, which is the silent-wrong-output class this project treats as the characteristic bug (AGENTS.md §3).

Repro

<?php
class A { public string $p = 'hi'; }
class B extends A {}
echo (new B)->p;

Measured in php-compiler:22.04-dev, on a tree containing the AOT link fix from #31894 (without it nothing links at all):

case Zend 8.2.32 AOT
class A { public string $p = 'hi'; } (new A)->p hi hi
class B extends A {} (new B)->p — typed hi PHP Fatal error: Uncaught Error: Typed property A::$p must not be accessed before initialization
class B extends A {} (new B)->p — untyped hi PHP Warning: Undefined property: A::$p then empty

Note the error names A::$p — the declaring class — so the property appears to be registered against the parent while the subclass's instance initialisation never writes the default.

Why it matters

This is not an edge case. Any class hierarchy where a base class declares a property with a default is broken under AOT, which is most real PHP code. The untyped variant produces wrong output rather than an error, so a program can silently compute the wrong answer.

How it was found

Two other AOT defects reported around the same time — var_dump aborting with rc=134 and Exception::getMessage() segfaulting — turned out to be symptoms of the duplicate-memset link failure in #31894 and now match Zend exactly. This one survives that fix and is independent.

Done when

  • class A { public string $p = 'hi'; } class B extends A {} echo (new B)->p; prints hi under AOT
  • the untyped variant likewise prints hi with no warning
  • a compliance case covers both, plus a two-level hierarchy (C extends B extends A)

Activity

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

    area:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions