reference/json/functions/json-last-error.xml
8cdc6621f9826d04abc3e50438c010804d7e8683
...
...
@@ -13,7 +13,8 @@
13
13
<void />
14
14
</methodsynopsis>
15
15
<para>
16
-
Returns the last error (if any) occurred during the last JSON encoding/decoding.
16
+
Returns the last error (if any) occurred during the last JSON encoding/decoding,
17
+
which did not specify <constant>JSON_THROW_ON_ERROR</constant>.
17
18
</para>
18
19
</refsect1>
19
20

...
...
@@ -67,7 +68,37 @@
67
68
<row>
68
69
<entry><constant>JSON_ERROR_UTF8</constant></entry>
69
70
<entry>Malformed UTF-8 characters, possibly incorrectly encoded</entry>
70
-
<entry>PHP 5.3.3</entry>
71
+
<entry></entry>
72
+
</row>
73
+
<row>
74
+
<entry><constant>JSON_ERROR_RECURSION</constant></entry>
75
+
<entry>One or more recursive references in the value to be encoded</entry>
76
+
<entry></entry>
77
+
</row>
78
+
<row>
79
+
<entry><constant>JSON_ERROR_INF_OR_NAN</constant></entry>
80
+
<entry>
81
+
One or more
82
+
<link linkend="language.types.float.nan"><constant>NAN</constant></link>
83
+
or <link linkend="function.is-infinite"><constant>INF</constant></link>
84
+
values in the value to be encoded
85
+
</entry>
86
+
<entry></entry>
87
+
</row>
88
+
<row>
89
+
<entry><constant>JSON_ERROR_UNSUPPORTED_TYPE</constant></entry>
90
+
<entry>A value of a type that cannot be encoded was given</entry>
91
+
<entry></entry>
92
+
</row>
93
+
<row>
94
+
<entry><constant>JSON_ERROR_INVALID_PROPERTY_NAME</constant></entry>
95
+
<entry>A property name that cannot be encoded was given</entry>
96
+
<entry></entry>
97
+
</row>
98
+
<row>
99
+
<entry><constant>JSON_ERROR_UTF16</constant></entry>
100
+
<entry>Malformed UTF-16 characters, possibly incorrectly encoded</entry>
101
+
<entry></entry>
71
102
</row>
72
103
</tbody>
73
104
</tgroup>
...
...
@@ -157,6 +188,31 @@ bool(true)
157
188
</screen>
158
189
</example>
159
190
</para>
191
+
<para>
192
+
<example>
193
+
<title><function>json_last_error</function> and <constant>JSON_THROW_ON_ERROR</constant></title>
194
+
<programlisting role="php">
195
+
<![CDATA[
196
+
<?php
197
+
// An invalid UTF8 sequence which causes JSON_ERROR_UTF8
198
+
json_encode("\xB1\x31");
199
+

200
+
// The following does not cause a JSON error
201
+
json_encode('okay', JSON_THROW_ON_ERROR);
202
+

203
+
// The global error state has not been changed by the former json_encode()
204
+
var_dump(json_last_error() === JSON_ERROR_UTF8);
205
+
?>
206
+
]]>
207
+
</programlisting>
208
+
&example.outputs;
209
+
<screen>
210
+
<![CDATA[
211
+
bool(true)
212
+
]]>
213
+
</screen>
214
+
</example>
215
+
</para>
160
216
</refsect1>
161
217

162
218
<refsect1 role="seealso">
163
219