reference/json/functions/json-encode.xml
19e8122137a1d42ed60f17fe2c0c2b69b0b2d16b
...
...
@@ -9,17 +9,23 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>string</type><methodname>json_encode</methodname>
12
+
<type class="union"><type>string</type><type>false</type></type><methodname>json_encode</methodname>
13
13
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
14
-
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
14
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
15
15
<methodparam choice="opt"><type>int</type><parameter>depth</parameter><initializer>512</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Returns a string containing the JSON representation of the supplied
19
-
<parameter>value</parameter>.
19
+
<parameter>value</parameter>. If the parameter is an &array; or &object;,
20
+
it will be serialized recursively.
20
21
</para>
21
22
<para>
22
-
The encoding is affected by the supplied <parameter>options</parameter>
23
+
If a value to be serialized is an object, then by default only publicly visible
24
+
properties will be included. Alternatively, a class may implement <interfacename>JsonSerializable</interfacename>
25
+
to control how its values are serialized to <acronym>JSON</acronym>.
26
+
</para>
27
+
<para>
28
+
The encoding is affected by the supplied <parameter>flags</parameter>
23
29
and additionally the encoding of float values depends on the value of
24
30
<link linkend="ini.serialize-precision">serialize_precision</link>.
25
31
</para>
...
...
@@ -34,7 +40,7 @@
34
40
<listitem>
35
41
<para>
36
42
The <parameter>value</parameter> being encoded. Can be any type except
37
-
a <type>resource</type>.
43
+
a &resource;.
38
44
</para>
39
45
<para>
40
46
All string data must be UTF-8 encoded.
...
...
@@ -43,21 +49,26 @@
43
49
</listitem>
44
50
</varlistentry>
45
51
<varlistentry>
46
-
<term><parameter>options</parameter></term>
52
+
<term><parameter>flags</parameter></term>
47
53
<listitem>
48
54
<para>
49
-
Bitmask consisting of <constant>JSON_HEX_QUOT</constant>,
55
+
Bitmask consisting of
56
+
<constant>JSON_FORCE_OBJECT</constant>,
57
+
<constant>JSON_HEX_QUOT</constant>,
50
58
<constant>JSON_HEX_TAG</constant>,
51
59
<constant>JSON_HEX_AMP</constant>,
52
60
<constant>JSON_HEX_APOS</constant>,
61
+
<constant>JSON_INVALID_UTF8_IGNORE</constant>,
62
+
<constant>JSON_INVALID_UTF8_SUBSTITUTE</constant>,
53
63
<constant>JSON_NUMERIC_CHECK</constant>,
64
+
<constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant>,
65
+
<constant>JSON_PRESERVE_ZERO_FRACTION</constant>,
54
66
<constant>JSON_PRETTY_PRINT</constant>,
67
+
<constant>JSON_UNESCAPED_LINE_TERMINATORS</constant>,
55
68
<constant>JSON_UNESCAPED_SLASHES</constant>,
56
-
<constant>JSON_FORCE_OBJECT</constant>,
57
-
<constant>JSON_PRESERVE_ZERO_FRACTION</constant>,
58
69
<constant>JSON_UNESCAPED_UNICODE</constant>,
59
-
<constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant>. The behaviour of these
60
-
constants is described on the
70
+
<constant>JSON_THROW_ON_ERROR</constant>.
71
+
The behaviour of these constants is described on the
61
72
<link linkend="json.constants">JSON constants</link> page.
62
73
</para>
63
74
</listitem>
...
...
@@ -77,7 +88,7 @@
77
88
<refsect1 role="returnvalues">
78
89
&reftitle.returnvalues;
79
90
<para>
80
-
Returns a JSON encoded <type>string</type> on success &return.falseforfailure;.
91
+
Returns a JSON encoded &string; on success &return.falseforfailure;.
81
92
</para>
82
93
</refsect1>
83
94

...
...
@@ -94,58 +105,33 @@
94
105
</thead>
95
106
<tbody>
96
107
<row>
97
-
<entry>7.1.0</entry>
98
-
<entry>
99
-
<link linkend="ini.serialize-precision">serialize_precision</link> is
100
-
used instead of <link linkend="ini.precision">precision</link> when
101
-
encoding double values.
102
-
</entry>
103
-
</row>
104
-
<row>
105
-
<entry>5.6.6</entry>
106
-
<entry>
107
-
<constant>JSON_PRESERVE_ZERO_FRACTION</constant>
108
-
<parameter>option</parameter> was added.
109
-
</entry>
110
-
</row>
111
-
<row>
112
-
<entry>5.5.0</entry>
113
-
<entry>
114
-
<parameter>depth</parameter> parameter was added.
115
-
</entry>
116
-
</row>
117
-
<row>
118
-
<entry>5.5.0</entry>
108
+
<entry>7.3.0</entry>
119
109
<entry>
120
-
<constant>JSON_PARTIAL_OUTPUT_ON_ERROR</constant> option was added.
110
+
<constant>JSON_THROW_ON_ERROR</constant>
111
+
<parameter>flags</parameter> was added.
121
112
</entry>
122
113
</row>
123
114
<row>
124
-
<entry>5.5.0</entry>
115
+
<entry>7.2.0</entry>
125
116
<entry>
126
-
The return value on failure was changed from <literal>null</literal>
127
-
string to &false;.
117
+
<constant>JSON_INVALID_UTF8_IGNORE</constant>, and
118
+
<constant>JSON_INVALID_UTF8_SUBSTITUTE</constant>
119
+
<parameter>flags</parameter> were added.
128
120
</entry>
129
121
</row>
130
122
<row>
131
-
<entry>5.4.0</entry>
132
-
<entry>
133
-
<constant>JSON_PRETTY_PRINT</constant>,
134
-
<constant>JSON_UNESCAPED_SLASHES</constant>, and
135
-
<constant>JSON_UNESCAPED_UNICODE</constant>
136
-
<parameter>options</parameter> were added.
137
-
</entry>
138
-
</row>
139
-
<row>
140
-
<entry>5.3.3</entry>
123
+
<entry>7.1.0</entry>
141
124
<entry>
142
-
<constant>JSON_NUMERIC_CHECK</constant> <parameter>option</parameter> was added.
125
+
<constant>JSON_UNESCAPED_LINE_TERMINATORS</constant>
126
+
<parameter>flags</parameter> was added.
143
127
</entry>
144
128
</row>
145
129
<row>
146
-
<entry>5.3.0</entry>
130
+
<entry>7.1.0</entry>
147
131
<entry>
148
-
The <parameter>options</parameter> parameter was added.
132
+
<link linkend="ini.serialize-precision">serialize_precision</link> is
133
+
used instead of <link linkend="ini.precision">precision</link> when
134
+
encoding <type>float</type> values.
149
135
</entry>
150
136
</row>
151
137
</tbody>
...
...
@@ -178,7 +164,7 @@ echo json_encode($arr);
178
164

179
165
<example>
180
166
<title>
181
-
A <function>json_encode</function> example showing some options in use
167
+
A <function>json_encode</function> example showing some flags in use
182
168
</title>
183
169
<programlisting role="php">
184
170
<![CDATA[
...
...
@@ -388,8 +374,7 @@ string(2) "12"
388
374
<para>
389
375
Like the reference JSON encoder, <function>json_encode</function> will
390
376
generate JSON that is a simple value (that is, neither an object nor an
391
-
array) if given a <type>string</type>, <type>integer</type>,
392
-
<type>float</type> or <type>boolean</type> as an input
377
+
array) if given a &string;, &integer;, &float; or &boolean; as an input
393
378
<parameter>value</parameter>. While most decoders will accept these values
394
379
as valid JSON, some may not, as the specification is ambiguous on this
395
380
point.
...
...
@@ -413,7 +398,6 @@ string(2) "12"
413
398
</para>
414
399
</refsect1>
415
400
</refentry>
416
-

417
401
<!-- Keep this comment at the end of the file
418
402
Local variables:
419
403
mode: sgml
420
404