Skip to content

Language: bare self/parent typed properties reject valid assignments — Zend accepts (?self/unions OK) (zend_execute / TypeCheck) #31835

Description

@PurHur

Category

Language: · php-src-strict · typed properties (self / parent)

Problem

Instance properties declared with a bare self or parent type must accept assignments that satisfy the early-bound class (same class / subclass for self; parent class / subclass for parent), including constructor-promoted public self $x. On master 2026-08-17, VM throws TypeError: Cannot assign A to property A::$x of type self (and the analogous parent error) even when assigning $this / a valid parent instance.

Control: ?self and self|string / parent|string already match Zend on this tree — only the bare self / parent forms are wrong. Param/return self types also match (not this bug).

Probed 2026-08-17 — host Zend PHP 8.2 vs php bin/vm.php.

Repro Zend 8.2+ VM (2026-08-17)
$a->x = $a with public self $x self_ok A TypeError “… of type self”
$b->x = $b on subclass inheriting self child_ok B TypeError
$c->x = new P with public parent $x parent_ok P TypeError “… of type parent”
promoted public function __construct(public self $x) promoted_ok TypeError
public ?self $x assign $this OK OK (control)

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_prop_type_self.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_prop_type_self.php'

Done when

  • Bare self / parent property assigns match Zend (instance, inherited, promoted)
  • ?self / union controls and wrong-type TypeErrors stay correct
  • Compliance .phpt guard under test/compliance/cases/ for property self/parent
  • php-src-strict; no php-compiler-strict shortcut

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