Skip to content

Fix object array offset TypeError for isset/array_key_exists (#6500) - #6508

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6500-illegal-offset-object
Jun 6, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6500-illegal-offset-object

Conversation

@PurHur

@PurHur PurHur commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extend EnumCaseSupport::rejectIllegalArrayOffset() to reject plain objects and arrays (not only enum cases) with Zend-compatible TypeError: Illegal offset type.
  • Fix array_key_exists()/key_exists() VM builtin and JIT lowered paths to raise TypeError instead of internal LogicException / silent false on object keys.
  • Fix JIT isset() hashtable offset checks to emit TypeError for object indices (matching VM offsetIsSet message).
  • Add compliance test test/compliance/cases/language/illegal_offset_object.phpt.

php-src reference: Zend/zend_hash.c illegal offset checks; ext/standard/array.c array_key_exists().

Verification

Issue repro:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "
class K {} \$a=[];
try { var_export(array_key_exists(new K, \$a)); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\n\"; }
try { var_export(isset(\$a[new K])); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\n\"; }
try { var_export(key_exists(new K, \$a)); } catch (Throwable \$e) { echo get_class(\$e), \": \", \$e->getMessage(), \"\n\"; }
" 2>&1'

Output:

TypeError: Illegal offset type
TypeError: Illegal offset type in isset or empty
TypeError: Illegal offset type

Targeted compliance:

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

Result: OK (1 test, 1 assertion)

Regression (enum illegal offset):

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

Result: OK (2 tests, 2 assertions)

Closes #6500

Made with Cursor

Extend illegal-offset guards to reject plain objects and arrays on hash
lookup paths so Zend-compatible TypeError replaces internal LogicException.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit d61c694 into master Jun 6, 2026
@PurHur
PurHur deleted the agent/issue-6500-illegal-offset-object branch June 6, 2026 00:42
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.

Runtime: object array offset — isset()/array_key_exists() must TypeError (Illegal offset type)

1 participant