Skip to content

Language: asymmetric visibility on constructor-promoted properties (zend_compile.c parity) #4690

Description

@PurHur

Category

language

Problem

PHP 8.4 asymmetric visibility (public private(set)) on constructor-promoted properties must compile and enforce the same rules as ordinary properties. This compiler lowers asymmetric visibility via AsymmetricVisibilityRewriter / propertySetVisibility for explicit properties, but promoted parameters with private(set) may lose set-visibility metadata or allow illegal writes from the constructor body/global scope.

php-src reference

Repro (today)

<?php
class User {
    public function __construct(
        public private(set) string $name,
    ) {}
}
$u = new User('alice');
echo $u->name, "\n";
try {
    $u->name = 'bob';
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
php repro.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'
Runtime Expected (Zend) Actual today
Zend alice + cannot modify private(set) message —
VM/JIT same may allow external write or wrong compile error

Scope (this repo)

Layer Path
Compiler lib/Compiler.php promoted param → property (asymmetricSetVisibilityFromCfgOp)
Rewriter lib/SourcePreprocessor/AsymmetricVisibilityRewriter.php
VM / JIT lib/VM.php, lib/JIT/AsymmetricVisibilityGuard.php
Tests test/compliance/cases/language/asymmetric_visibility_promoted.phpt

Done when

  • Repro matches Zend on VM and JIT (catchable Error on external write)
  • Writes from inside class / constructor still allowed
  • ./script/ci-fast.sh --filter asymmetric_visibility_promoted green

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