svn: /phpdoc/ja/trunk/reference/json/functions/ json-decode.xml
[email protected] (Yoshinari Takaoka) Thu, 10 Dec 2020 22:37:08 +0000
| Newsgroups | php.doc.ja |
|---|---|
| Message-ID | <[email protected]> |
mumumu Thu, 10 Dec 2020 22:37:08 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=352004
Log:
json_decode: better explanation and example of 'depth' parameter
Closes GH-275.
Changed paths:
U phpdoc/ja/trunk/reference/json/functions/json-decode.xml
Modified: phpdoc/ja/trunk/reference/json/functions/json-decode.xml
===================================================================
--- phpdoc/ja/trunk/reference/json/functions/json-decode.xml 2020-12-10 22:30:14 UTC (rev 352003)
+++ phpdoc/ja/trunk/reference/json/functions/json-decode.xml 2020-12-10 22:37:08 UTC (rev 352004)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351406 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 352001 Maintainer: takagi Status: ready -->
<!-- Credits: mumumu -->
<refentry xml:id="function.json-decode" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
@@ -55,7 +55,7 @@
<term><parameter>depth</parameter></term>
<listitem>
<para>
- ユーザー指定の再帰の深さ。
+ デコードするデータのネストの深さの最大値。
</para>
</listitem>
</varlistentry>
@@ -87,7 +87,7 @@
<literal>null</literal> はそれぞれ &true;、&false;
そして &null; として返されます。
<parameter>json</parameter> のデコードに失敗したり
- エンコードされたデータが再帰制限を超えているなどの場合、&null; を返します。
+ エンコードされたデータがネストの最大値を超えているなどの場合、&null; を返します。
</para>
</refsect1>
@@ -226,7 +226,7 @@
<programlisting role="php">
<![CDATA[
<?php
-// データをエンコードします
+// データをエンコードします。ネストの深さは4です (array -> array -> array -> string)
$json = json_encode(
array(
1 => array(
@@ -242,20 +242,12 @@
)
);
-// エラーを定義します
-$constants = get_defined_constants(true);
-$json_errors = array();
-foreach ($constants["json"] as $name => $value) {
- if (!strncmp($name, "JSON_ERROR_", 11)) {
- $json_errors[$value] = $name;
- }
-}
+// さまざまな深さのエラーを表示します
+var_dump(json_decode($json, true, 4));
+echo 'Last error: ', json_last_error_msg(), PHP_EOL, PHP_EOL;
-// さまざまな深さのエラーを表示します
-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;
-}
+var_dump(json_decode($json, true, 3));
+echo 'Last error: ', json_last_error_msg(), PHP_EOL, PHP_EOL;
?>
]]>
</programlisting>
@@ -281,10 +273,10 @@
}
}
}
-Last error: JSON_ERROR_NONE
+Last error: No error
NULL
-Last error: JSON_ERROR_DEPTH
+Last error: Maximum stack depth exceeded
]]>
</screen>
</example>