Skip to content

Stdlib: array_key_exists() TypeError for non-array second argument (#4722) - #4762

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-array-key-exists-typeerror-4722
Jun 3, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/stdlib-array-key-exists-typeerror-4722

Conversation

@PurHur

@PurHur PurHur commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace LogicException with Zend-matching TypeError when array_key_exists() receives a non-array second argument (VM via VmArray::requireArrayParam, JIT/AOT via JitArrayElem / TypeErrorRaise).
  • Report object class names (not generic object) in VmArray::valueTypeLabel() for php-src parity on array param errors.

php-src reference: ext/standard/array.cPHP_FUNCTION(array_key_exists) / Z_PARAM_ARRAY

Closes #4722

Verification

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

Output (Zend + VM match):

TypeError: array_key_exists(): Argument #2 ($array) must be of type array, C given
TypeError: array_key_exists(): Argument #2 ($array) must be of type array, C given
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit --filter array_key_exists_non_array'
OK (3 tests, 7 assertions)

AOT lint + abort on non-array string operand:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/compile.php -l test/repro-maintainer/array_key_exists_non_array.php'
# exit 0

OUT=$(mktemp) && php bin/compile.php -o "$OUT" test/fixtures/aot/cases/array_key_exists_non_array.phpt
# AotTest: exit 134 (TypeError abort) — OK

Test plan

  • Issue repro on VM matches Zend TypeError class + message
  • Compliance PHPT array_key_exists_non_array.phpt
  • AOT fixture array_key_exists_non_array.phpt (exit 134)
  • Existing VM array_key_exists* tests green (5/5)

Made with Cursor

Use VmArray/JitArrayElem requireArrayParam helpers so VM and AOT/JIT
paths raise Zend-matching TypeError instead of LogicException; report
object class names in VmArray type labels for parity with php-src.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit a8df893 into master Jun 3, 2026
@PurHur
PurHur deleted the agent/stdlib-array-key-exists-typeerror-4722 branch June 3, 2026 01:40
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.

Stdlib: array_key_exists() — TypeError for non-array second argument (ext/standard/array.c Z_PARAM_ARRAY)

1 participant