Skip to content

Language: property hooks with asymmetric set visibility set (protected) => — parse fails (zend_property_hooks.c) #6898

Description

@PurHur

Category

language · php-src-strict · PHP 8.4

Problem

PHP 8.4 property hooks may declare asymmetric set visibility on the set hook:

public string $x {
    get => 'g';
    set (protected) => $value;
}

php-src accepts this; this compiler fails to parse (Syntax error, unexpected '(' on the set hook line). Other property-hook gaps (#4821, #4701, …) assume hooks parse; this blocks asymmetric hook visibility entirely.

php-src reference

Repro

<?php
declare(strict_types=1);

class C {
    public string $x {
        get => 'g';
        set (protected) => $value;
    }
}

$c = new C();
echo $c->x, "\n";          // g
$c->x = 'n';               // Error from global scope (protected set)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "class C{public string \$x{get=>\"g\"; set(protected)=>\$value;}} \$c=new C; echo \$c->x,\"\n\";" 2>&1 | head -5
'

Scope (PHP-in-PHP first)

Layer Path
Parser/Rewriter extend property-hook grammar or pre-parse normalization (similar to AsymmetricVisibilityRewriter)
VM/JIT enforce protected/private set on hook writes (Error parity)
Tests test/compliance/cases/language/property_hook_asymmetric_set.phpt

Done when

  • Repro parses; get hook returns g
  • Assignment from global scope throws catchable Error (protected set)
  • Assignment from allowed scope succeeds
  • ./script/ci-fast.sh --filter property_hook_asymmetric green on VM

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 6, 2026
  2. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    Merged via #6980.

    Verification (VM):
    ```bash
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php -r "class C{public string $x{get=>"g"; set(protected)=>$value;}} $c=new C; echo $c->x,"\n"; try{$c->x="n";}catch(Error $e){echo get_class($e),": ",$e->getMessage(),"\n";} echo $c->x,"\n";"'
    ```
    Prints g, then Error: Cannot modify protected(set) property C::$x from global scope, then g.

    `vendor/bin/phpunit --filter property_hook_asymmetric` — OK (3 tests).

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