Skip to content

Fix empty() on uninitialized typed properties — php-src parity (#6787) - #6873

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6787-empty-uninit-typed-property
Jun 6, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6787-empty-uninit-typed-property

Conversation

@PurHur

@PurHur PurHur commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • empty() on uninitialized typed instance and static properties now returns true without throwing, matching Zend/php-src (zend_object_handlers.c) and reverting Language: empty() on uninitialized typed property must throw Error (zend_object_handlers.c) #4912 throw semantics.
  • VM: emptyObjectProperty() and TYPE_EMPTY short-circuit on TypedPropertyCheck::isUninitialized() before read/boolval.
  • JIT: EmptyObjectPropertyHelper selects true when slot type is TYPE_UNDEFINED instead of emitting TypedPropertyUninitGuard.
  • Compliance empty_uninitialized_typed_property.phpt updated for php-src EXPECT.

php-src reference: Zend/zend_object_handlers.c, ext/standard/basic_functions.c (PHP_EMPTY)

PHP implementation: lib/VM.php, lib/JIT/EmptyObjectPropertyHelper.php, lib/JIT.php

Closes #6787

Test plan

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/6787_empty_uninit_typed.php
php bin/vm.php test/repro/6787_empty_uninit_typed.php
vendor/bin/phpunit --filter empty_uninitialized
'

Output (VM repro):

isset i=false empty i=true
isset s=false empty s=true

PHPUnit:

OK (2 tests, 2 assertions)  # VMTest + JITTest empty_uninitialized

Made with Cursor

Zend returns true for empty() on uninitialized typed instance and static
properties without throwing; revert #4912 throw semantics and guard VM/JIT
lowering so uninitialized slots short-circuit to empty before read guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
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: empty() on uninitialized typed properties — php-src returns true without throw (regression vs #4912, zend_object_handlers.c)

1 participant