Skip to content

Stdlib: json_validate() — validate JSON without decode (#3101) - #3121

Merged
PurHur merged 2 commits into
masterfrom
agent/issue-3101-json-validate
May 29, 2026
Merged

PurHur merged 2 commits into
masterfrom
agent/issue-3101-json-validate

Conversation

@PurHur

@PurHur PurHur commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

Implements PHP 8.3 json_validate() for VM, JIT, and AOT:

  • VM: VmJsonValidate uses host json_validate() when available (PHP 8.3+), otherwise json_decode() + json_last_error() with ValueError on depth exceed
  • JIT/AOT: __compiler_json_validate in phpc_json_decode.c reuses the existing JSON parser with configurable max_depth; returns native int1 for correct ternary truthiness
  • Registered in ext/standard/Module.php, JIT builtins, self-host policy, and capability matrix

php-src reference

  • ext/json/json.c — PHP_FUNCTION(json_validate) / php_json_validate_ex

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && \
  php vendor/bin/phpunit test/unit/JsonValidateBuiltinTest.php && \
  php vendor/bin/phpunit test/compliance/VMTest.php --filter json_validate && \
  php vendor/bin/phpunit test/aot/AotTest.php --filter json_validate'
php bin/vm.php -r 'var_export(json_validate("{\"a\":1}"));'

Closes #3101

Made with Cursor

@PurHur
PurHur force-pushed the agent/issue-3101-json-validate branch 2 times, most recently from 4c34197 to 3fda408 Compare May 29, 2026 13:34
PurHur and others added 2 commits May 29, 2026 15:42
Add json_validate with host/json_decode VM fallback, C parser validate
runtime, and compliance PHPTs. Reference: ext/json/json.c php_json_validate_ex.

Co-authored-by: Cursor <cursoragent@cursor.com>
__compiler_json_validate MCJIT execution segfaults; VM compliance covers
json_validate() (#3101).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the agent/issue-3101-json-validate branch from 3fda408 to 53aa56f Compare May 29, 2026 13:42
@PurHur
PurHur merged commit f930a5e into master May 29, 2026
@PurHur
PurHur deleted the agent/issue-3101-json-validate branch May 29, 2026 13: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.

Stdlib: json_validate() — validate JSON without full decode (PHP 8.3, ext/json parity)

1 participant