-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy path005.phpt
187 lines (160 loc) · 4.49 KB
/
005.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--TEST--
serialize()/unserialize() objects
--FILE--
<?php
// This test verifies that old and new style (un)serializing do not interfere.
function do_autoload($class_name)
{
if ($class_name != 'autoload_not_available')
{
require_once(__DIR__ . '/' . strtolower($class_name) . '.inc');
}
echo __FUNCTION__ . "($class_name)\n";
}
function unserializer($class_name)
{
echo __METHOD__ . "($class_name)\n";
switch($class_name)
{
case 'TestNAOld':
eval("class TestNAOld extends TestOld {}");
break;
case 'TestNANew':
eval("class TestNANew extends TestNew {}");
break;
case 'TestNANew2':
eval("class TestNANew2 extends TestNew {}");
break;
default:
echo "Try autoloader\n";
if (!spl_autoload_functions()) {
spl_autoload_register(function ($class_name) { do_autoload($class_name); });
}
spl_autoload_call($class_name);
break;
}
}
ini_set('unserialize_callback_func', 'unserializer');
class TestOld
{
function serialize()
{
echo __METHOD__ . "()\n";
}
function unserialize($serialized)
{
echo __METHOD__ . "()\n";
}
function __wakeup()
{
echo __METHOD__ . "()\n";
}
function __sleep()
{
echo __METHOD__ . "()\n";
return array();
}
}
class TestNew implements Serializable
{
protected static $check = 0;
function serialize()
{
echo __METHOD__ . "()\n";
switch(++self::$check)
{
case 1:
return NULL;
case 2:
return "2";
}
}
function unserialize($serialized)
{
echo __METHOD__ . "()\n";
}
function __wakeup()
{
echo __METHOD__ . "()\n";
}
function __sleep()
{
echo __METHOD__ . "()\n";
}
}
echo "===O1===\n";
var_dump($ser = serialize(new TestOld));
var_dump(unserialize($ser));
echo "===N1===\n";
var_dump($ser = serialize(new TestNew));
var_dump(unserialize($ser));
echo "===N2===\n";
var_dump($ser = serialize(new TestNew));
var_dump(unserialize($ser));
echo "===NAOld===\n";
var_dump(unserialize('O:9:"TestNAOld":0:{}'));
echo "===NANew===\n";
var_dump(unserialize('O:9:"TestNANew":0:{}'));
echo "===NANew2===\n";
var_dump(unserialize('C:10:"TestNANew2":0:{}'));
echo "===AutoOld===\n";
var_dump(unserialize('O:19:"autoload_implements":0:{}'));
// Now we have an autoloader, that will be called before the old style header.
// If the old style handler also fails to register the class then the object
// becomes an incomplete class instance.
echo "===AutoNA===\n";
var_dump(unserialize('O:22:"autoload_not_available":0:{}'));
?>
--EXPECTF--
Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
===O1===
TestOld::__sleep()
string(18) "O:7:"TestOld":0:{}"
TestOld::__wakeup()
object(TestOld)#%d (0) {
}
===N1===
TestNew::serialize()
string(2) "N;"
NULL
===N2===
TestNew::serialize()
string(19) "C:7:"TestNew":1:{2}"
TestNew::unserialize()
object(TestNew)#%d (0) {
}
===NAOld===
unserializer(TestNAOld)
TestOld::__wakeup()
object(TestNAOld)#%d (0) {
}
===NANew===
unserializer(TestNANew)
Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
Warning: Erroneous data format for unserializing 'TestNANew' in %s005.php on line %d
Warning: unserialize(): Error at offset 19 of 20 bytes in %s on line %d
bool(false)
===NANew2===
unserializer(TestNANew2)
Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
TestNew::unserialize()
object(TestNANew2)#%d (0) {
}
===AutoOld===
unserializer(autoload_implements)
Try autoloader
do_autoload(autoload_interface)
do_autoload(autoload_implements)
object(autoload_implements)#%d (0) {
}
===AutoNA===
do_autoload(autoload_not_available)
unserializer(autoload_not_available)
Try autoloader
do_autoload(autoload_not_available)
do_autoload(autoload_not_available)
Warning: unserialize(): Function unserializer() hasn't defined the class it was called for in %s005.php on line %d
object(__PHP_Incomplete_Class)#%d (1) {
["__PHP_Incomplete_Class_Name"]=>
string(22) "autoload_not_available"
}