Category
stdlib · php-src-strict
Problem
When the JSON_THROW_ON_ERROR flag is passed, invalid JSON must throw JsonException (extends Exception). This compiler throws TypeError (or generic errors) instead, so user catch (JsonException $e) handlers never run.
php-src reference
Repro
<?php
try {
json_decode('{', null, 512, JSON_THROW_ON_ERROR);
echo "no throw\n";
} catch (JsonException $e) {
echo "JsonException\n";
} catch (Throwable $e) {
echo get_class($e), "\n";
}
php repro.php # Zend: JsonException
php bin/vm.php repro.php # VM today: TypeError
Additional probes (php-src-strict)
json_encode("\xB1\x31", JSON_THROW_ON_ERROR); // invalid UTF-8 → JsonException
json_decode('{"a":}', flags: JSON_THROW_ON_ERROR); // syntax error → JsonException
Scope (PHP-in-PHP)
| Path |
Work |
ext/json/VmJson.php (or ext/standard/) |
Map parser/encoder failures to JsonException when JSON_THROW_ON_ERROR set |
ext/json/Module.php |
Ensure JsonException class registered |
lib/JIT/Builtin/ |
JIT json decode/encode throw path parity when flags are compile-time known |
| Tests |
test/compliance/cases/ext/json_throw_on_error.phpt |
Done when
- Invalid
json_decode(..., JSON_THROW_ON_ERROR) throws JsonException with catchable type
json_encode UTF-8 / depth / recursion failures with throw flag throw JsonException
- Without
JSON_THROW_ON_ERROR, legacy null + json_last_error() behavior unchanged (php-src-strict)
./script/docker-exec.sh -- php bin/vm.php test/compliance/cases/ext/json_throw_on_error.phpt green
Category
stdlib· php-src-strictProblem
When the
JSON_THROW_ON_ERRORflag is passed, invalid JSON must throwJsonException(extendsException). This compiler throwsTypeError(or generic errors) instead, so usercatch (JsonException $e)handlers never run.php-src reference
ext/json/php_json.c—php_json_decode_ex,JSON_THROW_ON_ERRORext/json/php_json.h—php_json_throw_exceptionext/json/json_encoder.c— encode failures with throw flagRepro
Additional probes (php-src-strict)
Scope (PHP-in-PHP)
ext/json/VmJson.php(orext/standard/)JsonExceptionwhenJSON_THROW_ON_ERRORsetext/json/Module.phpJsonExceptionclass registeredlib/JIT/Builtin/test/compliance/cases/ext/json_throw_on_error.phptDone when
json_decode(..., JSON_THROW_ON_ERROR)throwsJsonExceptionwith catchable typejson_encodeUTF-8 / depth / recursion failures with throw flag throwJsonExceptionJSON_THROW_ON_ERROR, legacynull+json_last_error()behavior unchanged (php-src-strict)./script/docker-exec.sh -- php bin/vm.php test/compliance/cases/ext/json_throw_on_error.phptgreen