Skip to content

Language: property hooks without get — read/isset/empty must throw Error (zend_property_hooks.c, pairs #4821) #6484

Description

@PurHur

Category

language · php-src-strict

Problem

PHP 8.4+ allows write-only hooked properties (public string $x { set => …; } with no get). Reading such a property (including isset() / empty()) must throw a catchable Error — Zend refuses access when no get hook exists. This compiler currently exposes the raw backing value after a set-hook write and reports isset() as true.

Pairs #4821 (get-only → assignment must Error).

php-src reference

Repro (VM today — wrong)

./script/docker-exec.sh -- php bin/vm.php test/repro-maintainer/issue_writeonly_hook_read.php
# prints: HI

./script/docker-exec.sh -- php bin/vm.php test/repro-maintainer/issue_writeonly_hook_isset.php
# prints: bool(true)

Zend PHP 8.4+ (host comparison when available):

<?php
class C {
    public string $x {
        set => $this->x = strtoupper($value);
    }
}
$c = new C();
$c->x = 'hi';
try { echo $c->x, "\n"; } catch (Error $e) { echo $e->getMessage(), "\n"; }
try { var_dump(isset($c->x)); } catch (Error $e) { echo $e->getMessage(), "\n"; }

Expected

  • echo $c->x → Error: Cannot read property C::$x without get hook (wording per Zend)
  • isset($c->x) / empty($c->x) → same Error (no silent true)

Implementation hints (PHP-in-PHP)

  • VM: lib/VM.php property-hook fetch / isset paths — reject when hook metadata has set but no get (lib/VM/PropertyHookSupport.php or equivalent)
  • JIT/AOT: mirror in lib/JIT/PropertyHookDispatch.php (compliance JIT/AOT when issue requires)
  • Add test/compliance/cases/language/property_hook_writeonly_read.phpt + property_hook_writeonly_isset.phpt

Verification

./script/docker-exec.sh -- php bin/vm.php test/repro-maintainer/issue_writeonly_hook_read.php
./script/ci-fast.sh --filter 'property_hook_writeonly'

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