Skip to content

Language: asymmetric visibility private(get) / protected(get) — parse + read guards (zend_compile.c) #5059

Description

@PurHur

Category

language

Problem

PHP 8.4 asymmetric property visibility includes a read side (public private(get), protected private(get), etc.), not only private(set) / protected(set) / public(set) on writes.

This repo’s lib/Ast/AsymmetricVisibilityRewriter.php rewrites set modifiers only (MARKER_PREFIX = phpc-asymmetric-set:). There is no marker or VM/JIT guard for get visibility, and no compliance coverage for private(get) / protected(get).

Zend rejects illegal read/write combinations at compile time and enforces read access in zend_object_handlers.c.

php-src reference

Repro (expected Zend vs today)

<?php
class Box {
    public private(get) string $secret = 'hidden';
}
$b = new Box();
echo $b->secret, "\n"; // global scope: Error — cannot access private(get) property
php repro.php
# Zend: Error: Cannot access private(get) property Box::$secret from global scope

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# Today: likely parse/compile failure or treats as ordinary public read (parity drift)

Also verify combined forms compile when valid in Zend, e.g. public protected(set) string $x.

Scope (this repo)

Area Path
Parse/rewrite lib/Ast/AsymmetricVisibilityRewriter.php, lib/Runtime.php preprocessor
PHPCfg flags lib/Compiler.phppropertySetVisibility + new get visibility storage
VM read guard lib/VM.php — mirror asymmetricPropertyWriteMessage() for reads
JIT/AOT lib/JIT/AsymmetricVisibilityGuard.php — read-side LLVM guard (phase 2 OK)
Tests test/compliance/cases/language/asymmetric_visibility_private_get.phpt

Done when

  • private(get) / protected(get) properties parse and compile on VM
  • Illegal read from outer scope raises catchable Error matching Zend text
  • Existing private(set) tests still pass (asymmetric_visibility_*.phpt)
  • ./script/ci-fast.sh --filter asymmetric_visibility_private_get green

Related

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