Skip to content

Language: list()/array destructuring on property hooks must use get/set hooks (zend_property_hooks.c) #6434

Description

@PurHur

Category

language

Problem

PHP 8.4 property hooks must participate in list destructuring and array destructuring ([$obj->prop] = …, […, $obj->prop, …] = …). Zend invokes the set hook on assignment targets and the get hook when a hooked property is read as a destructuring source.

This compiler lowers hooks via lib/SourcePreprocessor/PropertyHooks.php + indirect writes in lib/VM.php, but list/array destructuring still writes backing storage (or skips hooks), diverging from php-src.

Pairs with #6426 (by-ref assign), #6427 (compound assign), #6424 (++/--) — same zend_property_hooks.c dispatch family.

php-src reference

Repro

Save as test/repro-maintainer/parity_property_hook_list_destructure.php:

<?php
class Box {
    private string $_v = '';
    public string $label {
        get => $this->_v;
        set => $this->_v = '[' . $value . ']';
    }
}
$c = new Box();
[$c->label] = ['hi'];
echo $c->label, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_property_hook_list_destructure.php
php bin/vm.php test/repro-maintainer/parity_property_hook_list_destructure.php
'
Runtime Output
Zend PHP 8.4+ [hi] (set hook ran)
VM today likely hi or hook bypass (wrong)

Compliance: add test/compliance/cases/language/property_hook_list_destructure.phpt

Scope (this repo)

Path Work
lib/VM.php List/assign lowering — route hooked property lvalues through set hook
lib/JIT/PropertyHookDispatch.php Mirror for JIT/AOT when destructuring is lowered
lib/Compiler.php Ensure list targets on hooked props emit hook-aware stores
Tests VM + JIT PHPT (JIT may defer if Block::requiresVmLowering)

PHP-in-PHP first — no new C runtime branches.

Done when

  • Repro prints [hi] on VM matching Zend
  • Nested/mixed list with hooked + plain props matches Zend on tested subset
  • ./script/ci-fast.sh --filter property_hook_list green
  • JIT/AOT documented in matrix (native lowering or VM deferral with issue link)

Verification

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

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