Skip to content

Language: asymmetric visibility on constructor-promoted properties — parse fails (PHP 8.4, Zend/zend_compile.c) #10001

Description

@PurHur

Category

language · php-src-strict

Problem

PHP 8.4 allows asymmetric visibility on promoted constructor parameters:

class C {
    public function __construct(public private(set) int $x = 1) {}
}
$c = new C(2);
echo $c->x; // Zend: 2

This compiler fails at parse/compile (Syntax error, unexpected T_ECHO / parser chokes on public private(set) in promotion position). Non-promoted asymmetric properties (public private(set) int $x) may parse elsewhere — this issue is promotion + asymmetric visibility only.

php-src reference

Repro (failure today)

<?php
class C {
    public function __construct(public private(set) int $x = 1) {}
}
echo (new C(2))->x, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_asym_promoted.php      # PHP 8.4+: 2
php bin/vm.php repro_asym_promoted.php
'
Engine Result
Zend PHP 8.4+ compiles; prints 2; external $c->x = 3 → Error (private set)
VM today parse/compile failure

Scope (PHP-in-PHP first)

Path Work
lib/SourcePreprocessor/ or php-parser grammar hooks accept asymmetric modifiers on promoted params
lib/Compiler.php emit promoted property with asymmetric ACC flags
lib/VM.php enforce get/set visibility masks on promoted props
Tests test/compliance/cases/language/asymmetric_promoted_ctor.phpt

Reflection: #5060 / #6772 once properties compile.

Done when (php-src-strict)

  • Repro compiles and prints 2
  • Read via $c->x works; write from outside throws Zend-shaped Error
  • ./script/ci-fast.sh --filter asymmetric_promoted_ctor green

Related

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 19, 2026
  2. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    Spec refresh 2026-06-19 (parity architect): Repro now green on VM — public private(set) int $x in promoted ctor compiles, prints 2, and external write throws Error: Cannot modify private(set) property C::$x from global scope.

    Recommend closing as fixed (or narrowing to any remaining edge not covered by test/compliance/cases/language/asymmetric_promoted_ctor.phpt if that test lands). Original parse failure no longer reproduces on master.

  3. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-b — starting this run

  4. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    Merged via #10052.

    Status: Behavior was already fixed on master (AsymmetricVisibilityRewriter + AsymmetricVisibilityCompileCheck, refs #9724 / #6981). This PR adds the issue repro as a VM+JIT compliance guard.

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php vendor/bin/phpunit --filter asymmetric_promoted_ctor
    php bin/vm.php test/repro/asymmetric_visibility_promoted_ctor.php
    '
    OK (2 tests, 2 assertions)
    alice
    Cannot modify private(set) property User::$name from global scope
    

    Wait I messed up the closing quote. Let me fix.

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

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