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.php — TYPE_PRE_INC, TYPE_POST_INC, TYPE_PRE_DEC, TYPE_POST_DEC paths; reuse enforceVirtualPropertyHookWrite / get-hook read |
| Compiler |
lib/Compiler.php — compileIncDecExpr 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
Category
languageProblem
#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 inlib/VM.phpbut does not dispatch property hooks on inc/dec lvalues — hooked properties mutate backing storage or skip hooks.php-src reference
Zend/zend_property_hooks.c— inc/dec on hooked propertiesZend/zend_execute.c—ZEND_PRE_INC_OBJ,ZEND_POST_INC_OBJ, etc.Zend/zend_compile.c— inc/dec onPROP_HOOKlvaluesRepro (failure today)
bin/vm.phptoday++$c->count$c->count++String increment (
$s++on hooked string) and--must follow same get/set pattern per php-src.Scope (this repo)
lib/VM.php—TYPE_PRE_INC,TYPE_POST_INC,TYPE_PRE_DEC,TYPE_POST_DECpaths; reuseenforceVirtualPropertyHookWrite/ get-hook readlib/Compiler.php—compileIncDecExprif lvalue metadata neededlib/JIT/PropertyHookDispatch.php,lib/JIT.php— mirror VMtest/compliance/cases/language/property_hook_incdec.phptPHP-in-PHP first: hook dispatch stays in PHP VM/JIT lowering.
Done when
$s++on hooked string property matches Zend (str_incrementsemantics via hooks)Error(same as plain assign, Language: property hooks without set — assignment must throw Error (zend_property_hooks.c) #4821)./script/ci-fast.sh --filter property_hook_incdecgreenphp-src-strict
Default — inc/dec must not write backing storage directly when hooks are defined.
Related