svn: /phpdoc/en/trunk/reference/json/functions/ json-encode.xml json-last-error.xml

From: Date: Sat, 30 Apr 2011 13:13:52 +0000
Subject: svn: /phpdoc/en/trunk/reference/json/functions/ json-encode.xml json-last-error.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-8045@lists.php.net to get a copy of this message
salathe Sat, 30 Apr 2011 13:13:52 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=310659 Log: json_last_error() reports on json_encode() errors too (doc #54075) Bug: http://bugs.php.net/54075 (Open) Wrong information on json_last_error() Changed paths: U phpdoc/en/trunk/reference/json/functions/json-encode.xml U phpdoc/en/trunk/reference/json/functions/json-last-error.xml Modified: phpdoc/en/trunk/reference/json/functions/json-encode.xml =================================================================== --- phpdoc/en/trunk/reference/json/functions/json-encode.xml 2011-04-30 12:57:23 UTC (rev 310658) +++ phpdoc/en/trunk/reference/json/functions/json-encode.xml 2011-04-30 13:13:52 UTC (rev 310659) @@ -165,11 +165,22 @@ </para> </refsect1> + <refsect1 role="notes"> + &reftitle.notes; + <note> + <para> + In the event of a failure to encode, <function>json_last_error</function> + can be used to determine the exact nature of the error. + </para> + </note> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><function>json_decode</function></member> + <member><function>json_last_error</function></member> </simplelist> </para> </refsect1> Modified: phpdoc/en/trunk/reference/json/functions/json-last-error.xml =================================================================== --- phpdoc/en/trunk/reference/json/functions/json-last-error.xml 2011-04-30 12:57:23 UTC (rev 310658) +++ phpdoc/en/trunk/reference/json/functions/json-last-error.xml 2011-04-30 13:13:52 UTC (rev 310659) @@ -13,7 +13,7 @@ <void /> </methodsynopsis> <para> - Returns the last error (if any) occurred by last JSON parsing. + Returns the last error (if any) occurred during the last JSON encoding/decoding. </para> </refsect1> @@ -125,6 +125,31 @@ </screen> </example> </para> + <para> + <example> + <title><function>json_last_error</function> with <function>json_encode</function></title> + <programlisting role="php"> +<![CDATA[ +<?php +// An invalid UTF8 sequence +$text = "\xB1\x31"; + +$json = json_encode($text); +$error = json_last_error(); + +var_dump($json, $error === JSON_ERROR_UTF8); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +string(4) "null" +bool(true) +]]> + </screen> + </example> + </para> </refsect1> <refsect1 role="seealso"> @@ -132,6 +157,7 @@ <para> <simplelist> <member><function>json_decode</function></member> + <member><function>json_encode</function></member> </simplelist> </para> </refsect1>

« previous php.doc.cvs (#8045) next »