Skip to content

Fix ??= on property hooks — backing null-check + get/set hooks (#6472) - #6493

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6472-property-hook-nullcoalesce
Jun 6, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6472-property-hook-nullcoalesce

Conversation

@PurHur

@PurHur PurHur commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • ??= on hooked properties now null-checks backing storage (via propertyHookRegistry set/get backing fields), not the get-hook return value — matching Zend when backing is null but get returns a default.
  • Coalesce lowering emits property fetch read on the left branch and property fetch write + assign on the right branch so VM routes through get/set hooks (dispatchPropertySetHookAssign).
  • Adds compliance PHPT covering assign-when-null and no-op-when-backing-set.

php-src reference

  • Zend/zend_property_hooks.c — coalesce assign on hooked properties

PHP implementation

  • lib/Compiler.phpcompileCoalesce property fetch read/write branches + issetForCoalesceAssign flag
  • lib/VM.phpobjectPropertyIsSetForCoalesceAssign()
  • lib/OpCode.phpissetForCoalesceAssign on TYPE_ISSET

Closes #6472

Verification

Issue repro:

./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 bin/vm.php /tmp/hook_nullcoalesce.php'

Output: assigned

Compliance:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter property_hook_nullcoalesce_assign test/compliance/VMTest.php'

Output: OK (1 test, 1 assertion)

Regression (related coalesce + property hooks):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "property_hook_nullcoalesce_assign|property_hook_set_arrow|coalesce_assign|property_hook_unset" test/compliance/VMTest.php'

Output: OK (9 tests, 9 assertions)

Made with Cursor

…).

Coalesce-assign on hooked properties now tests backing storage for null,
reads via get hook on the taken branch, and writes via set hook when assigning.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 4b61bbd into master Jun 6, 2026
@PurHur
PurHur deleted the agent/issue-6472-property-hook-nullcoalesce branch June 6, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: ??= on property hooks must invoke get/set hooks (zend_property_hooks.c)

1 participant