Skip to content

Language: PHP 8.4 property hooks — get/set on properties (Zend parity) #3145

Description

@PurHur

Category

language

Problem

PHP 8.4 property hooks (get / set on properties) are not parsed or lowered. php-parser / php-cfg may need upgrades; compiler has no hook dispatch on property read/write.

Framework DTOs and validated properties (email, status codes) increasingly use hooks instead of manual __get/__set.

php-src reference

Repro — set hook (failure today)

Save as property_hook_set.php:

<?php
class User {
    public string $email {
        set (string $value) {
            if (!str_contains($value, '@')) {
                throw new InvalidArgumentException('email');
            }
            $this->email = $value;
        }
    }
}

$user = new User();
$user->email = 'bad';
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php property_hook_set.php'
php property_hook_set.php   # Zend 8.4+: InvalidArgumentException
Runtime Today
Zend PHP 8.4+ InvalidArgumentException: email
bin/vm.php Parse / compile error (unsupported property syntax)

Repro — get hook (phase 2 in same issue or follow-up)

<?php
class Box {
    public int $total {
        get => $this->items * $this->unit;
    }
    public function __construct(private int $items, private int $unit) {}
}
$box = new Box(3, 10);
echo $box->total, "\n";

Done when: prints 30 on VM like Zend 8.4.

Scope (this repo)

Module Path
Parser/cfg vendor php-parser / php-cfg patches — preserve hook bodies on property nodes
Compiler lib/Compiler.php — hook dispatch on property fetch/assign
VM lib/VM.php — invoke hook closures with correct $this; backing value storage
Lint lib/Lint/UnsupportedRegistry.php — remove mapping when VM path exists
Tests test/compliance/cases/language/property_hook_set.phpt, property_hook_get.phpt
Matrix script/capability-syntax.php — row for property hooks

Not: internal_* permanent shims; full JIT/AOT in v1 (VM-first).

Done when

  • property_hook_set.php compiles; invalid email throws InvalidArgumentException on VM
  • Valid assign persists; read returns stored value
  • get hook repro prints 30 (or tracked child issue linked)
  • ./script/ci-fast.sh --filter property_hook green
  • docs/capabilities-syntax.md row Property hooks → VM yes

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter property_hook'
./script/docker-exec.sh -- bash -lc 'php script/capability-syntax.php'

Dependencies

Links

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 / JITenhancementNew 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