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 git.master_jit, git.master
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>" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.15 ms | 407 KiB | 5 Q