Skip to content

Fix isset()/empty() on property hooks — invoke get hook (#4701) - #7495

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4701-property-hook-isset-empty
Jun 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4701-property-hook-isset-empty

Conversation

@PurHur

@PurHur PurHur commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Recover empty($obj->prop) operand when php-cfg clears Empty_.expr, so lowering uses TYPE_EMPTY_OBJECT_PROPERTY like isset() uses TYPE_ISSET (zend_property_hooks.c).
  • emptyObjectProperty() on hooked properties now runs the get hook and tests truthiness instead of negating isset semantics.
  • Preserve null from get hooks on nullable typed properties (?string) instead of weak-coercing to "".

php-src reference

  • Zend/zend_property_hooks.c — isset/empty on hooked properties
  • Zend/zend_object_handlers.c — zend_std_has_property

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro-maintainer/property_hook_isset.php'

Output:

true
false

Full compliance case (get-only + null get hook):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php vendor/bin/phpunit --filter property_hook_isset'
OK (1 test, 1 assertion)

Write-only regression:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php vendor/bin/phpunit --filter property_hook_writeonly_isset'
OK (1 test, 1 assertion)

Closes #4701

Made with Cursor

empty($obj->hook) now lowers to TYPE_EMPTY_OBJECT_PROPERTY when php-cfg
clears Empty_.expr, and emptyObjectProperty evaluates get-hook truthiness.
Nullable get-hook null returns are preserved instead of coercing to "".

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 49f4e65 into master Jun 7, 2026
@PurHur
PurHur deleted the agent/issue-4701-property-hook-isset-empty branch June 7, 2026 12:07
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: property hooks — isset() and empty() must use get hook (zend_property_hooks.c)

1 participant