language/oop5/serialization.xml
1f407ffe61c42c203c99ff0bacc1ae82b3414621
...
...
@@ -1,5 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
+
<!-- TODO Rewrite to remove usage of "you" and talk about __serialize/_unserialize -->
3
4
<sect1 xml:id="language.oop5.serialization" xmlns="http://docbook.org/ns/docbook">
4
5
<title>Object Serialization</title>
5
6
<title>Serializing objects - objects in sessions</title>
...
...
@@ -31,7 +32,7 @@
31
32
<programlisting role="php">
32
33
<![CDATA[
33
34
<?php
34
-
// classa.inc:
35
+
// A.php:
35
36
36
37
class A {
37
38
public $one = 1;
...
...
@@ -43,7 +44,7 @@
43
44
44
45
// page1.php:
45
46

46
-
include("classa.inc");
47
+
include "A.php";
47
48
48
49
$a = new A;
49
50
$s = serialize($a);
...
...
@@ -53,7 +54,7 @@
53
54
// page2.php:
54
55
55
56
// this is needed for the unserialize to work properly.
56
-
include("classa.inc");
57
+
include "A.php";
57
58

58
59
$s = file_get_contents('store');
59
60
$a = unserialize($s);
...
...
@@ -66,16 +67,6 @@
66
67
</informalexample>
67
68

68
69
<para>
69
-
If an application is using sessions and uses
70
-
<function>session_register</function> to register objects, these objects
71
-
are serialized automatically at the end of each PHP page, and are
72
-
unserialized automatically on each of the following pages. This means that
73
-
these objects can show up on any of the application's pages once they become
74
-
part of the session. However, the <function>session_register</function> is
75
-
removed since PHP 5.4.0.
76
-
</para>
77
-
78
-
<para>
79
70
It is strongly recommended that if an application serializes objects, for use
80
71
later in the application, that the application includes the class definition
81
72
for that object throughout the application. Not doing so might result in an
...
...
@@ -86,8 +77,8 @@
86
77
87
78
<para>
88
79
So if in the example above <varname>$a</varname> became part of a session
89
-
by running <literal>session_register("a")</literal>, you should include the
90
-
file <literal>classa.inc</literal> on all of your pages, not only <filename>page1.php</filename>
80
+
by adding a new key to the <varname>$_SESSION</varname> superglobal array, you should include the
81
+
file <literal>A.php</literal> on all of your pages, not only <filename>page1.php</filename>
91
82
and <filename>page2.php</filename>.
92
83
</para>
93
84

...
...
@@ -100,7 +91,6 @@
100
91
serialize a subset of the object's properties.
101
92
</para>
102
93
</sect1>
103
-
104
94
<!-- Keep this comment at the end of the file
105
95
Local variables:
106
96
mode: sgml
107
97