Skip to content

Language: Typed properties, union types, and readonly (PHP 8+) #169

Description

@PurHur

Category

language

Problem

class C { public string $name; public int|string $id; public readonly string $code; } parses, but VM does not enforce property types on write. Assigning int to string $x succeeds silently (verified May 2026). This blocks Zend parity for Router/config objects and self-host code using typed properties throughout lib/.

php-src reference

Repro (failure today)

Typed property write

<?php
class C { public string $x = ''; }
$c = new C();
$c->x = 123;
echo $c->x;
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# prints 123 (Zend: TypeError)

Readonly second assign

<?php
class C { public readonly string $code = 'x'; }
$c = new C();
$c->code = 'y';
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_readonly.php'
# succeeds (Zend: Error "Cannot modify readonly property")

Union accept/reject

<?php
class C { public int|string $id = 0; }
$c = new C();
$c->id = 'ok';
$c->id = [];

Zend: first assign ok, second TypeError.

Scope (this repo)

Module Path
Compiler metadata lib/Compiler.php — persist Type on TYPE_DECLARE_PROPERTY
VM assign lib/VM.phpTYPE_PROPERTY_ASSIGN enforce + readonly
Types lib/Type.php or php-types assignability helpers
Uninitialized read coordinate #3429
Tests test/compliance/cases/language/typed_property_*.phpt
Phase 2 JIT/AOT after VM green (#55, #58)

Done when

Verification

./script/ci-fast.sh --filter typed_property
php script/bootstrap-inventory.php --check  # typed props in lib/ should stop warning-only assigns

Links

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 / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-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