Category
language
Problem
Null-coalesce assignment (??=) on a property hook must read via the get hook and write via the set hook when the backing value is unset/null — same as plain $obj->prop = … assignment in php-src.
This compiler treats ??= like a raw property write: VM emits "Attempt to read property … on null" warnings and never invokes hooks.
Distinct from #6427 (compound +=/.= operators) — ??= uses coalesce+assign opcodes (lib/Compiler.php coalesce paths).
php-src reference
Repro
<?php
class C {
private ?string $x = null;
public string $y {
get => $this->x ?? 'default';
set => $this->x = $value;
}
}
$c = new C();
$c->y ??= 'assigned';
echo $c->y, "\n";
// Zend: assigned
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/hook_nullcoalesce.php <<'"'"'PHPEOF'"'"'
<?php
class C {
private ?string $x = null;
public string $y { get => $this->x ?? "default"; set => $this->x = $value; }
}
$c = new C();
$c->y ??= "assigned";
echo $c->y, "\n";
PHPEOF
php /tmp/hook_nullcoalesce.php
php bin/vm.php /tmp/hook_nullcoalesce.php
'
Today: VM prints warnings and wrong output (not assigned).
Scope
| Path |
Work |
lib/Compiler.php |
compileCoalesce / assign paths — hook-aware dim fetch for ??= lvalues |
lib/VM.php |
Coalesce left branch must call get hook; right branch must call set hook |
lib/JIT.php |
Mirror when property has lowered hooks |
Done when
Strictness
php-src-strict
Related
Category
languageProblem
Null-coalesce assignment (
??=) on a property hook must read via the get hook and write via the set hook when the backing value is unset/null — same as plain$obj->prop = …assignment in php-src.This compiler treats
??=like a raw property write: VM emits "Attempt to read property … on null" warnings and never invokes hooks.Distinct from #6427 (compound
+=/.=operators) —??=uses coalesce+assign opcodes (lib/Compiler.phpcoalesce paths).php-src reference
Zend/zend_property_hooks.c— get/set dispatch on assignZend/zend_compile.c—??=loweringRepro
Today: VM prints warnings and wrong output (not
assigned).Scope
lib/Compiler.phpcompileCoalesce/ assign paths — hook-aware dim fetch for??=lvalueslib/VM.phplib/JIT.phpDone when
assignedon VM without warnings??=is a no-op (get hook value preserved)test/compliance/cases/language/property_hook_nullcoalesce_assign.phptgreenStrictness
php-src-strict
Related