mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

* Add `json_validate(string $json, int $depth = 512, int $flags = 0): bool` from https://wiki.php.net/rfc/json_validate * In json_validate, use a different set of C no-op functions for creating/updating arrays/objects when validating while reusing the unmodified parser/scanner code * Forbid unsupported flags in json_validate() * Remove test of passing NULL as parameter (normal behavior of https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg for internal functions) Co-authored-by: jcm <juan.carlos.morales@tradebyte.com>
64 lines
848 B
PHP
64 lines
848 B
PHP
--TEST--
|
|
json_validate() - compare against json_decode() for different types of inputs
|
|
--FILE--
|
|
<?php
|
|
|
|
$inputs = [
|
|
'""',
|
|
'"string"',
|
|
'1234',
|
|
'123.45',
|
|
'-123',
|
|
'null',
|
|
'true',
|
|
'false',
|
|
'{}',
|
|
'[]',
|
|
'-',
|
|
'',
|
|
];
|
|
|
|
foreach ($inputs as $input) {
|
|
var_dump($input, json_decode($input), json_validate($input));
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
string(2) """"
|
|
string(0) ""
|
|
bool(true)
|
|
string(8) ""string""
|
|
string(6) "string"
|
|
bool(true)
|
|
string(4) "1234"
|
|
int(1234)
|
|
bool(true)
|
|
string(6) "123.45"
|
|
float(123.45)
|
|
bool(true)
|
|
string(4) "-123"
|
|
int(-123)
|
|
bool(true)
|
|
string(4) "null"
|
|
NULL
|
|
bool(true)
|
|
string(4) "true"
|
|
bool(true)
|
|
bool(true)
|
|
string(5) "false"
|
|
bool(false)
|
|
bool(true)
|
|
string(2) "{}"
|
|
object(stdClass)#1 (0) {
|
|
}
|
|
bool(true)
|
|
string(2) "[]"
|
|
array(0) {
|
|
}
|
|
bool(true)
|
|
string(1) "-"
|
|
NULL
|
|
bool(false)
|
|
string(0) ""
|
|
NULL
|
|
bool(false)
|