Skip to content

Language: static property union type hints (T1|T2) — PHP 8.4 parse + runtime (zend_compile.c) #8726

Description

@PurHur

Category

language

Problem

PHP 8.4 allows union types on static properties (e.g. public static string|int $p = 0;). php-src parses and enforces these via zend_compile.c / typed-property handlers. This compiler rejects the syntax with a parse error (unexpected '|', expecting T_AMPERSAND…) or fails later on DNF reconstruction.

Self-host and modern library code targeting PHP 8.4 cannot compile.

php-src reference

Repro

test/repro/static_property_union_type.php:

<?php
class C {
    public static string|int $p = 'x';
}
echo C::$p, "\n";
C::$p = 42;
echo C::$p, "\n";
try {
    C::$p = 3.14;
} catch (TypeError $e) {
    echo 'TypeError: ', $e->getMessage(), "\n";
}
php test/repro/static_property_union_type.php   # PHP 8.4+
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/static_property_union_type.php'
Step Zend 8.4 VM today
Parse static string|int $p OK parse/compile failure
Read/write valid members OK —
Invalid assign TypeError —

Scope

  • Parser/type AST: php-parser + lib/Compiler/TypeReconstructor.php (extend beyond instance DNF Language: DNF types — union of intersections (PHP 8.2) #3094)
  • Compile checks: lib/Compiler/TypedPropertyCompileCheck.php (static branch)
  • VM stores: lib/VM.php static property writes, lib/VM/TypedPropertyCheck.php
  • JIT/AOT: static property assign lowering in lib/JIT/Builtin/Type/Object_.php

Done when

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: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