reference/json/jsonserializable/jsonserialize.xml
0a09554f3dd39c61b21ea7319ac7f93f781f9376
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="jsonserializable.jsonserialize" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>JsonSerializable::jsonSerialize</refname>
...
...
@@ -9,9 +8,9 @@
9
8

10
9
<refsect1 role="description">
11
10
&reftitle.description;
12
-
<methodsynopsis>
13
-
<modifier>abstract</modifier> <modifier>public</modifier> <type>mixed</type><methodname>JsonSerializable::jsonSerialize</methodname>
14
-
<void />
11
+
<methodsynopsis role="JsonSerializable">
12
+
<modifier>public</modifier> <type>mixed</type><methodname>JsonSerializable::jsonSerialize</methodname>
13
+
<void/>
15
14
</methodsynopsis>
16
15
<para>
17
16
Serializes the object to a value that can be serialized natively by
...
...
@@ -28,7 +27,7 @@
28
27
&reftitle.returnvalues;
29
28
<para>
30
29
Returns data which can be serialized by <function>json_encode</function>,
31
-
which is a value of any type other than a <type>resource</type>.
30
+
which is a value of any type other than a &resource;.
32
31
</para>
33
32
</refsect1>
34
33

...
...
@@ -38,17 +37,18 @@
38
37
<example>
39
38
<title>
40
39
<methodname>JsonSerializable::jsonSerialize</methodname> example
41
-
returning an <type>array</type>
40
+
returning an &array;
42
41
</title>
43
42
<programlisting role="php">
44
43
<![CDATA[
45
44
<?php
46
45
class ArrayValue implements JsonSerializable {
46
+
private $array;
47
47
public function __construct(array $array) {
48
48
$this->array = $array;
49
49
}
50
50

51
-
public function jsonSerialize() {
51
+
public function jsonSerialize(): mixed {
52
52
return $this->array;
53
53
}
54
54
}
...
...
@@ -72,12 +72,13 @@ echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
72
72
<example>
73
73
<title>
74
74
<methodname>JsonSerializable::jsonSerialize</methodname> example
75
-
returning an associative <type>array</type>
75
+
returning an associative &array;
76
76
</title>
77
77
<programlisting role="php">
78
78
<![CDATA[
79
79
<?php
80
80
class ArrayValue implements JsonSerializable {
81
+
private $array;
81
82
public function __construct(array $array) {
82
83
$this->array = $array;
83
84
}
...
...
@@ -105,14 +106,15 @@ echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
105
106
<example>
106
107
<title>
107
108
<methodname>JsonSerializable::jsonSerialize</methodname> example
108
-
returning an <type>integer</type>
109
+
returning an &integer;
109
110
</title>
110
111
<programlisting role="php">
111
112
<![CDATA[
112
113
<?php
113
114
class IntegerValue implements JsonSerializable {
115
+
private $number;
114
116
public function __construct($number) {
115
-
$this->number = (integer) $number;
117
+
$this->number = (int) $number;
116
118
}
117
119

118
120
public function jsonSerialize() {
...
...
@@ -134,12 +136,13 @@ echo json_encode(new IntegerValue(1), JSON_PRETTY_PRINT);
134
136
<example>
135
137
<title>
136
138
<methodname>JsonSerializable::jsonSerialize</methodname> example
137
-
returning a <type>string</type>
139
+
returning a &string;
138
140
</title>
139
141
<programlisting role="php">
140
142
<![CDATA[
141
143
<?php
142
144
class StringValue implements JsonSerializable {
145
+
private $string;
143
146
public function __construct($string) {
144
147
$this->string = (string) $string;
145
148
}
...
...
@@ -163,7 +166,6 @@ echo json_encode(new StringValue('Hello!'), JSON_PRETTY_PRINT);
163
166
</para>
164
167
</refsect1>
165
168
</refentry>
166
-

167
169
<!-- Keep this comment at the end of the file
168
170
Local variables:
169
171
mode: sgml
170
172