3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"1": "a"}'; $jsonValidate = function (string $json, int $depth = 512, int $flags = 0) { if (function_exists('json_validate')) { return json_validate($json, $depth, $flags); } $maxDepth = 0x7fffffff; if (0 !== $flags && \defined('JSON_INVALID_UTF8_IGNORE') && \JSON_INVALID_UTF8_IGNORE !== $flags) { throw new \ValueError('json_validate(): Argument #3 ($flags) must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)'); } if ($depth <= 0) { throw new \ValueError('json_validate(): Argument #2 ($depth) must be greater than 0'); } if ($depth > $maxDepth) { throw new \ValueError(sprintf('json_validate(): Argument #2 ($depth) must be less than %d', $maxDepth)); } json_decode($json, true, $depth, $flags); return \JSON_ERROR_NONE === json_last_error(); }; echo (int) $jsonValidate($json); var_dump($jsonValidate(...)); // error when function not exists var_dump(json_validate(...));
Output for 8.4.1 - 8.4.16, 8.5.0 - 8.5.1
1object(Closure)#1 (4) { ["name"]=> string(21) "{closure:/in/6sLa4:4}" ["file"]=> string(9) "/in/6sLa4" ["line"]=> int(4) ["parameter"]=> array(3) { ["$json"]=> string(10) "<required>" ["$depth"]=> string(10) "<optional>" ["$flags"]=> string(10) "<optional>" } } object(Closure)#2 (2) { ["function"]=> string(13) "json_validate" ["parameter"]=> array(3) { ["$json"]=> string(10) "<required>" ["$depth"]=> string(10) "<optional>" ["$flags"]=> string(10) "<optional>" } }
Output for 8.3.0 - 8.3.27, 8.3.29
1object(Closure)#1 (1) { ["parameter"]=> array(3) { ["$json"]=> string(10) "<required>" ["$depth"]=> string(10) "<optional>" ["$flags"]=> string(10) "<optional>" } } object(Closure)#2 (2) { ["function"]=> string(13) "json_validate" ["parameter"]=> array(3) { ["$json"]=> string(10) "<required>" ["$depth"]=> string(10) "<optional>" ["$flags"]=> string(10) "<optional>" } }
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.
Output for 8.1.34, 8.2.0 - 8.2.30
1object(Closure)#1 (1) { ["parameter"]=> array(3) { ["$json"]=> string(10) "<required>" ["$depth"]=> string(10) "<optional>" ["$flags"]=> string(10) "<optional>" } } Fatal error: Uncaught Error: Call to undefined function json_validate() in /in/6sLa4:27 Stack trace: #0 {main} thrown in /in/6sLa4 on line 27
Process exited with code 255.

preferences:
84.3 ms | 411 KiB | 5 Q