Skip to content

Language: ++/-- on property hooks must use get/set hooks (zend_property_hooks.c, pairs #6427) #6452

Description

@PurHur

Category

language

Problem

#6427 tracks compound assignment (+=, .=, …) on property hooks. Zend also routes pre/post increment and decrement (++$obj->prop, $obj->prop++, --) through get/set hooks: read current value via get hook, compute, write via set hook.

This compiler lowers TYPE_PRE_INC / TYPE_POST_INC / dec opcodes in lib/VM.php but does not dispatch property hooks on inc/dec lvalues — hooked properties mutate backing storage or skip hooks.

php-src reference

Repro (failure today)

<?php
class Counter {
    private int $n = 0;
    public int $count {
        get => $this->n;
        set => $this->n = $value;
    }
}
$c = new Counter();
echo $c->count, "\n";   // 0
$pre = ++$c->count;
echo "$pre {$c->count}\n"; // 1 1
$post = $c->count++;
echo "$post {$c->count}\n"; // 1 2
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_property_hook_incdec.php
php bin/vm.php repro_property_hook_incdec.php'
Step Zend bin/vm.php today
++$c->count get→add→set; returns new value likely wrong count / no set hook
$c->count++ returns old value; set hook runs likely wrong

String increment ($s++ on hooked string) and -- must follow same get/set pattern per php-src.

Scope (this repo)

Area Files
VM lib/VM.phpTYPE_PRE_INC, TYPE_POST_INC, TYPE_PRE_DEC, TYPE_POST_DEC paths; reuse enforceVirtualPropertyHookWrite / get-hook read
Compiler lib/Compiler.phpcompileIncDecExpr if lvalue metadata needed
JIT/AOT lib/JIT/PropertyHookDispatch.php, lib/JIT.php — mirror VM
Tests test/compliance/cases/language/property_hook_incdec.phpt

PHP-in-PHP first: hook dispatch stays in PHP VM/JIT lowering.

Done when

php-src-strict

Default — inc/dec must not write backing storage directly when hooks are defined.

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