<?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <appendix xml:id="json.constants" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> &reftitle.constants; &extension.constants; <para> The following constants indicate the type of error returned by <function>json_last_error</function> or stored as the <varname>code</varname> of a <classname>JsonException</classname>. </para> <variablelist> <varlistentry xml:id="constant.json-error-none"> <term> <constant>JSON_ERROR_NONE</constant> (&integer;) </term> <listitem> <simpara> No error has occurred. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-depth"> <term> <constant>JSON_ERROR_DEPTH</constant> (&integer;) </term> <listitem> <simpara> The maximum stack depth has been exceeded. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-state-mismatch"> <term> <constant>JSON_ERROR_STATE_MISMATCH</constant> (&integer;) </term> <listitem> <simpara> Occurs with underflow or with the modes mismatch. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-ctrl-char"> <term> <constant>JSON_ERROR_CTRL_CHAR</constant> (&integer;) </term> <listitem> <simpara> Control character error, possibly incorrectly encoded. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-syntax"> <term> <constant>JSON_ERROR_SYNTAX</constant> (&integer;) </term> <listitem> <simpara> Syntax error. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-utf8"> <term> <constant>JSON_ERROR_UTF8</constant> (&integer;) </term> <listitem> <simpara> Malformed UTF-8 characters, possibly incorrectly encoded. Available as of PHP 5.3.3. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-recursion"> <term> <constant>JSON_ERROR_RECURSION</constant> (&integer;) </term> <listitem> <simpara> The object or array passed to <function>json_encode</function> include recursive references and cannot be encoded. If the <constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> option was given, &null; will be encoded in the place of the recursive reference. Available as of PHP 5.5.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-inf-or-nan"> <term> <constant>JSON_ERROR_INF_OR_NAN</constant> (&integer;) </term> <listitem> <simpara> The value passed to <function>json_encode</function> includes either <link linkend="language.types.float.nan"><constant>NAN</constant></link> or <link linkend="function.is-infinite"><constant>INF</constant></link>. If the <constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> option was given, <literal>0</literal> will be encoded in the place of these special numbers. Available as of PHP 5.5.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-unsupported-type"> <term> <constant>JSON_ERROR_UNSUPPORTED_TYPE</constant> (&integer;) </term> <listitem> <simpara> A value of an unsupported type was given to <function>json_encode</function>, such as a &resource;. If the <constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> option was given, &null; will be encoded in the place of the unsupported value. Available as of PHP 5.5.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-invalid-property-name"> <term> <constant>JSON_ERROR_INVALID_PROPERTY_NAME</constant> (&integer;) </term> <listitem> <simpara> A key starting with \u0000 character was in the string passed to <function>json_decode</function> when decoding a JSON object into a PHP object. Available as of PHP 7.0.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-error-utf16"> <term> <constant>JSON_ERROR_UTF16</constant> (&integer;) </term> <listitem> <simpara> Single unpaired UTF-16 surrogate in unicode escape contained in the JSON string passed to <function>json_decode</function>. Available as of PHP 7.0.0. </simpara> </listitem> </varlistentry> </variablelist> <para> The following constants can be combined to form options for <function>json_decode</function>. </para> <variablelist> <varlistentry xml:id="constant.json-bigint-as-string"> <term> <constant>JSON_BIGINT_AS_STRING</constant> (&integer;) </term> <listitem> <simpara> Decodes large integers as their original string value. Available as of PHP 5.4.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-object-as-array"> <term> <constant>JSON_OBJECT_AS_ARRAY</constant> (&integer;) </term> <listitem> <simpara> Decodes JSON objects as PHP array. This option can be added automatically by calling <function>json_decode</function> with the second parameter equal to &true;. Available as of PHP 5.4.0. </simpara> </listitem> </varlistentry> </variablelist> <para> The following constants can be combined to form options for <function>json_encode</function>. </para> <variablelist> <varlistentry xml:id="constant.json-hex-tag"> <term> <constant>JSON_HEX_TAG</constant> (&integer;) </term> <listitem> <simpara> All < and > are converted to \u003C and \u003E. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-hex-amp"> <term> <constant>JSON_HEX_AMP</constant> (&integer;) </term> <listitem> <simpara> All & are converted to \u0026. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-hex-apos"> <term> <constant>JSON_HEX_APOS</constant> (&integer;) </term> <listitem> <simpara> All ' are converted to \u0027. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-hex-quot"> <term> <constant>JSON_HEX_QUOT</constant> (&integer;) </term> <listitem> <simpara> All " are converted to \u0022. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-force-object"> <term> <constant>JSON_FORCE_OBJECT</constant> (&integer;) </term> <listitem> <simpara> Outputs an object rather than an array when a non-associative array is used. Especially useful when the recipient of the output is expecting an object and the array is empty. Available as of PHP 5.3.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-numeric-check"> <term> <constant>JSON_NUMERIC_CHECK</constant> (&integer;) </term> <listitem> <simpara> Encodes numeric strings as numbers. Available as of PHP 5.3.3. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-pretty-print"> <term> <constant>JSON_PRETTY_PRINT</constant> (&integer;) </term> <listitem> <simpara> Use whitespace in returned data to format it. Available as of PHP 5.4.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-unescaped-slashes"> <term> <constant>JSON_UNESCAPED_SLASHES</constant> (&integer;) </term> <listitem> <simpara> Don't escape <literal>/</literal>. Available as of PHP 5.4.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-unescaped-unicode"> <term> <constant>JSON_UNESCAPED_UNICODE</constant> (&integer;) </term> <listitem> <simpara> Encode multibyte Unicode characters literally (default is to escape as \uXXXX). Available as of PHP 5.4.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-partial-output-on-error"> <term> <constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> (&integer;) </term> <listitem> <simpara> Substitute some unencodable values instead of failing. Available as of PHP 5.5.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-preserve-zero-fraction"> <term> <constant>JSON_PRESERVE_ZERO_FRACTION</constant> (&integer;) </term> <listitem> <simpara> Ensures that &float; values are always encoded as a float value. Available as of PHP 5.6.6. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-unescaped-line-terminators"> <term> <constant>JSON_UNESCAPED_LINE_TERMINATORS</constant> (&integer;) </term> <listitem> <simpara> The line terminators are kept unescaped when <constant>JSON_UNESCAPED_UNICODE</constant> is supplied. It uses the same behaviour as it was before PHP 7.1 without this constant. Available as of PHP 7.1.0. </simpara> </listitem> </varlistentry> </variablelist> <para> The following constants can be combined to form options for <function>json_decode</function> and <function>json_encode</function>. </para> <variablelist> <varlistentry xml:id="constant.json-invalid-utf8-ignore"> <term> <constant>JSON_INVALID_UTF8_IGNORE</constant> (&integer;) </term> <listitem> <simpara> Ignore invalid UTF-8 characters. Available as of PHP 7.2.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-invalid-utf8-substitute"> <term> <constant>JSON_INVALID_UTF8_SUBSTITUTE</constant> (&integer;) </term> <listitem> <simpara> Convert invalid UTF-8 characters to \0xfffd (Unicode Character 'REPLACEMENT CHARACTER') Available as of PHP 7.2.0. </simpara> </listitem> </varlistentry> <varlistentry xml:id="constant.json-throw-on-error"> <term> <constant>JSON_THROW_ON_ERROR</constant> (&integer;) </term> <listitem> <simpara> Throws <classname>JsonException</classname> if an error occurs instead of setting the global error state that is retrieved with <function>json_last_error</function> and <function>json_last_error_msg</function>. <constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> takes precedence over <constant>JSON_THROW_ON_ERROR</constant>. Available as of PHP 7.3.0. </simpara> </listitem> </varlistentry> </variablelist> </appendix> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"~/.phpdoc/manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->