mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Constants
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@312207 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
faa96c62bf
commit
0da36c5a16
4 changed files with 49 additions and 15 deletions
|
@ -32,6 +32,17 @@
|
|||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_STATE_MISMATCH</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Occurs with underflow or with the modes mismatch.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_ERROR_CTRL_CHAR</constant>
|
||||
|
@ -131,6 +142,18 @@
|
|||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_NUMERIC_CHECK</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Encodes numeric strings as numbers.
|
||||
Available since PHP 5.3.3.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</appendix>
|
||||
|
||||
|
|
|
@ -185,17 +185,18 @@ $json = json_encode(
|
|||
);
|
||||
|
||||
// Define the errors.
|
||||
$json_errors = array(
|
||||
JSON_ERROR_NONE => 'No error has occurred',
|
||||
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
|
||||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error',
|
||||
);
|
||||
$constants = get_defined_constants(true);
|
||||
$json_errors = array();
|
||||
foreach ($constants["json"] as $name => $value) {
|
||||
if (!strncmp($name, "JSON_ERROR_", 11)) {
|
||||
$json_errors[$value] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Show the errors for different depths.
|
||||
foreach(range(4, 3, -1) as $depth) {
|
||||
var_dump(json_decode($json, True, $depth));
|
||||
echo 'Last error : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
|
||||
echo 'Last error: ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
@ -222,10 +223,10 @@ array(1) {
|
|||
}
|
||||
}
|
||||
}
|
||||
Last error : No error has occurred
|
||||
Last error: JSON_ERROR_NONE
|
||||
|
||||
NULL
|
||||
Last error : The maximum stack depth has been exceeded
|
||||
Last error: JSON_ERROR_DEPTH
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<constant>JSON_HEX_TAG</constant>,
|
||||
<constant>JSON_HEX_AMP</constant>,
|
||||
<constant>JSON_HEX_APOS</constant>,
|
||||
<constant>JSON_NUMERIC_CHECK</constant>,
|
||||
<constant>JSON_FORCE_OBJECT</constant>.
|
||||
</para>
|
||||
</listitem>
|
||||
|
|
|
@ -50,13 +50,13 @@
|
|||
<entry></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_CTRL_CHAR</constant></entry>
|
||||
<entry>Control character error, possibly incorrectly encoded</entry>
|
||||
<entry><constant>JSON_ERROR_STATE_MISMATCH</constant></entry>
|
||||
<entry>Invalid or malformed JSON</entry>
|
||||
<entry></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>JSON_ERROR_STATE_MISMATCH</constant></entry>
|
||||
<entry>Invalid or malformed JSON</entry>
|
||||
<entry><constant>JSON_ERROR_CTRL_CHAR</constant></entry>
|
||||
<entry>Control character error, possibly incorrectly encoded</entry>
|
||||
<entry></entry>
|
||||
</row>
|
||||
<row>
|
||||
|
@ -97,17 +97,26 @@ foreach($json as $string)
|
|||
|
||||
switch(json_last_error())
|
||||
{
|
||||
case JSON_ERROR_NONE:
|
||||
echo ' - No errors';
|
||||
break;
|
||||
case JSON_ERROR_DEPTH:
|
||||
echo ' - Maximum stack depth exceeded';
|
||||
break;
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
echo ' - Underflow or the modes mismatch';
|
||||
break;
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
echo ' - Unexpected control character found';
|
||||
break;
|
||||
case JSON_ERROR_SYNTAX:
|
||||
echo ' - Syntax error, malformed JSON';
|
||||
break;
|
||||
case JSON_ERROR_NONE:
|
||||
echo ' - No errors';
|
||||
case JSON_ERROR_UTF8:
|
||||
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||
break;
|
||||
default:
|
||||
echo ' - Unknown error';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue