Skip to content

Language: asymmetric visibility — explicit read+set modifiers wrongly compile-fatal (regression vs #7099, PHP 8.4 RFC) #7308

Description

@PurHur

Category

language

Problem

PHP 8.4 asymmetric property visibility allows explicit read + set modifiers on the same property, e.g. public private(set) string $name (equivalent to shorthand private(set) string $name). Zend accepts public protected(set) and protected private(set) as well.

Closed #7099 added compile-time rejection in lib/Ast/AsymmetricVisibilityRewriter.php (rejectExplicitReadBeforeAsymmetricSetModifier()), but that diverges from php-src / the RFC: valid PHP 8.4 sources now fail with:

Multiple access type modifiers are not allowed

Shorthand private(set) alone still compiles (#3165).

php-src-strict: illegal combos such as protected public(set) must remain compile fatals.

php-src reference

Repro (failure today)

<?php
class A {
    public private(set) string $x = 'a';
}
class B {
    public protected(set) string $y = 'b';
}
class C {
    protected private(set) string $z = 'c';
}
echo "compiled\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php repro.php; echo vm_exit=$?
# Compare on PHP 8.4+ reference build when available
'

Observed (VM): parseAndCompile failure: Multiple access type modifiers are not allowed for all three classes.

Expected (php-src 8.4): compiles; read/write scopes enforced at runtime.

Implementation hints (PHP-in-PHP)

Pairs

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