Problem
No JSON builtins in ext/standard/. Small web apps serving APIs need JSON responses. Blocks #270 (004-ApiJson example) and #67 /api/status route.
Goal
json_encode / json_decode for arrays and strings (VM + JIT + AOT when other stdlib builtins do).
Implementation hints
v1 scope (arrays only)
- VM:
ext/standard/json_encode.php — delegate to PHP's json_encode/json_decode via existing builtin wrapper pattern (see htmlspecialchars, header).
- JIT: start with FFI/callout to libc is unnecessary; use
Jit* helper calling PHP runtime or embed minimal encoder for array<string|int|bool|null> + string values only.
- AOT: same module registration as JIT once VM path exists.
- Register in
ext/standard/Module.php; run script/capability-matrix.php and commit docs/capabilities.md diff.
Suggested files
| Area |
Path |
| VM builtin |
ext/standard/json_encode.php, json_decode.php |
| JIT |
ext/standard/JitJsonEncode.php (new, mirror JitHeader.php) |
| Tests |
test/real/cases/json_encode_api.phpt, compliance mirror |
| Lint registry |
lib/Lint/UnsupportedRegistry.php — remove if mapped |
PHPT sketch
--FILE--
<?php
header('Content-Type: application/json');
echo json_encode(['ok' => true, 'n' => 1]);
--EXPECT--
{"ok":true,"n":1}
Tasks
Scope v1
Acceptance criteria
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
./phpc run -r "header('Content-Type: application/json'); echo json_encode(['ok'=>true]);"
Output matches PHP 8. VM + JIT; AOT when bin/compile.php supports the builtin.
Dependencies
Verification (local only)
./script/ci-local.sh --filter json
Related
Problem
No JSON builtins in
ext/standard/. Small web apps serving APIs need JSON responses. Blocks #270 (004-ApiJsonexample) and #67/api/statusroute.Goal
json_encode/json_decodefor arrays and strings (VM + JIT + AOT when other stdlib builtins do).Implementation hints
v1 scope (arrays only)
ext/standard/json_encode.php— delegate to PHP'sjson_encode/json_decodevia existing builtin wrapper pattern (seehtmlspecialchars,header).Jit*helper calling PHP runtime or embed minimal encoder forarray<string|int|bool|null>+ string values only.ext/standard/Module.php; runscript/capability-matrix.phpand commitdocs/capabilities.mddiff.Suggested files
ext/standard/json_encode.php,json_decode.phpext/standard/JitJsonEncode.php(new, mirrorJitHeader.php)test/real/cases/json_encode_api.phpt, compliance mirrorlib/Lint/UnsupportedRegistry.php— remove if mappedPHPT sketch
Tasks
json_encodefor literal/array builds used by Examples: 004-ApiJson — minimal JSON API endpoint (lint-first) #270test/real/cases/Scope v1
JSON_THROW_ON_ERROR/JSON_INVALID_UTF8_*JsonSerializableobjects initiallyjson_decodesecond; shipjson_encodefirst for Examples: 004-ApiJson — minimal JSON API endpoint (lint-first) #270Acceptance criteria
Output matches PHP 8. VM + JIT; AOT when
bin/compile.phpsupports the builtin.Dependencies
http_response_code()optional for status JSON APIsVerification (local only)
Related