Skip to content

Commit 31ccf91

Browse files
committed
Partially deprecate Serializable
If Serializable is implemented, require that __serialize() and __unserialize() are implemented as well, else issue a deprecation warning.
1 parent c4f97a1 commit 31ccf91

22 files changed

+77
-10
lines changed

Zend/tests/bug64354.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ try {
2020
var_dump($e->getMessage());
2121
}
2222
?>
23-
--EXPECT--
23+
--EXPECTF--
24+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
2425
string(9) "serialize"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Serializable deprecation
3+
--FILE--
4+
<?php
5+
6+
interface I extends Serializable {}
7+
abstract class A implements Serializable {}
8+
9+
class C extends A implements I {
10+
public function serialize(): string {}
11+
public function unserialize(string $data) {}
12+
}
13+
14+
class D extends A implements I {
15+
public function serialize(): string {}
16+
public function unserialize(string $data) {}
17+
public function __serialize(): array {}
18+
public function __unserialize(array $data) {}
19+
}
20+
21+
?>
22+
--EXPECTF--
23+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line 6

Zend/tests/traits/interface_003.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var_dump(unserialize($o));
2121

2222
?>
2323
--EXPECTF--
24+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
2425
string(20) "C:3:"bar":6:{foobar}"
2526
string(6) "foobar"
2627
object(bar)#%d (0) {

Zend/zend_interfaces.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
429429
if (!class_type->unserialize) {
430430
class_type->unserialize = zend_user_unserialize;
431431
}
432+
if (!(class_type->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)
433+
&& (!class_type->__serialize || !class_type->__unserialize)) {
434+
zend_error(E_DEPRECATED, "The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them");
435+
}
432436
return SUCCESS;
433437
}
434438
/* }}}*/

ext/standard/tests/serialize/005.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ echo "===AutoNA===\n";
128128
var_dump(unserialize('O:22:"autoload_not_available":0:{}'));
129129
?>
130130
--EXPECTF--
131+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
131132
===O1===
132133
TestOld::__sleep()
133134
string(18) "O:7:"TestOld":0:{}"
@@ -152,12 +153,16 @@ object(TestNAOld)#%d (0) {
152153
===NANew===
153154
unserializer(TestNANew)
154155

156+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
157+
155158
Warning: Erroneous data format for unserializing 'TestNANew' in %s005.php on line %d
156159

157160
Notice: unserialize(): Error at offset 19 of 20 bytes in %s005.php on line %d
158161
bool(false)
159162
===NANew2===
160163
unserializer(TestNANew2)
164+
165+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
161166
TestNew::unserialize()
162167
object(TestNANew2)#%d (0) {
163168
}

ext/standard/tests/serialize/bug36424.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ echo "Done\n";
4444

4545
?>
4646
--EXPECTF--
47-
%aTEST
47+
-TEST
48+
49+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
50+
51+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
52+
53+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
4854
C:1:"c":108:{a:1:{s:1:"a";C:1:"a":81:{a:3:{s:1:"b";C:1:"b":30:{a:2:{s:1:"c";r:1;s:1:"a";r:3;}}s:1:"c";r:1;s:1:"a";r:3;}}}}
4955
bool(true)
5056
bool(true)

ext/standard/tests/serialize/bug64146.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ print $a->a[1]->b->c . "\n";
5353

5454
?>
5555
Done
56-
--EXPECT--
56+
--EXPECTF--
5757
Test
58+
59+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
5860
1
5961
2
6062
Done

ext/standard/tests/serialize/bug64354_3.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ try {
2525
var_dump($e->getMessage());
2626
}
2727
?>
28-
--EXPECT--
28+
--EXPECTF--
29+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
2930
string(6) "Failed"

ext/standard/tests/serialize/bug65481.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ $token = serialize($token);
3535

3636
?>
3737
Done
38-
--EXPECT--
38+
--EXPECTF--
3939
Test
40+
41+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
4042
Done

ext/standard/tests/serialize/bug70172.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function ptr2str($ptr)
4141
}
4242
?>
4343
--EXPECTF--
44+
Deprecated: The Serializable interface is deprecated. If you need to retain the Serializable interface for cross-version compatibility, you can suppress this warning by implementing __serialize() and __unserialize() in addition, which will take precedence over Serializable in PHP versions that support them in %s on line %d
4445
array(2) {
4546
[0]=>
4647
int(1)

0 commit comments

Comments
 (0)