Skip to content

Commit 807e5c2

Browse files
committed
Deprecate PDO::FETCH_SERIALIZE
1 parent 6326389 commit 807e5c2

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,9 @@ static bool pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode
11721172
/* no break; */
11731173

11741174
case PDO_FETCH_CLASS:
1175+
if (flags & PDO_FETCH_SERIALIZE) {
1176+
php_error_docref(NULL, E_DEPRECATED, "The PDO::FETCH_SERIALIZE mode is deprecated");
1177+
}
11751178
return 1;
11761179
}
11771180
}

ext/pdo/tests/bug_44409.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ $stmt = $db->query("SELECT * FROM test");
4040
print_r($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, "bug44409"));
4141

4242
?>
43-
--EXPECT--
43+
--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
45+
46+
Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
4447
Method called: bug44409::unserialize('Data from DB')
4548
Array
4649
(

ext/pdo/tests/pdo_018.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ var_dump($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_SERIAL
183183

184184
?>
185185
--EXPECTF--
186+
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
187+
188+
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
189+
190+
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
186191
string(1) "3"
187192
array(3) {
188193
[0]=>
@@ -221,6 +226,8 @@ array(4) {
221226
string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
222227
}
223228
===FAILURE===
229+
230+
Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
224231
Exception:SQLSTATE[HY000]: General error: cannot unserialize class
225232
===COUNT===
226233
string(1) "3"
@@ -249,6 +256,8 @@ array(3) {
249256
}
250257
}
251258
===FETCHCLASS===
259+
260+
Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
252261
TestBase::unserialize(a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
253262
TestDerived::unserialize()
254263
TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})

ext/pdo_mysql/tests/bug46292.phpt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,10 @@ MySQLPDOTest::skip();
1313
$pdoDb = MySQLPDOTest::factory();
1414

1515

16-
class myclass implements Serializable {
16+
class myclass {
1717
public function __construct() {
1818
printf("%s()\n", __METHOD__);
1919
}
20-
21-
public function serialize() {
22-
printf("%s()\n", __METHOD__);
23-
return "any data from serialize()";
24-
}
25-
26-
public function unserialize($dat) {
27-
printf("%s(%s)\n", __METHOD__, var_export($dat, true));
28-
return $dat;
29-
}
3020
}
3121

3222
class myclass2 extends myclass { }

ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ $db = MySQLPDOTest::factory();
120120
$db->exec('DROP TABLE IF EXISTS test');
121121
?>
122122
--EXPECTF--
123+
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
123124
Creating an object, serializing it and writing it to DB...
124125
myclass::singleton(Creating object)
125126
myclass::__construct(Creating object)
@@ -133,6 +134,10 @@ object(myclass)#4 (1) {
133134
}
134135

135136
Using PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE to fetch the object from DB and unserialize it...
137+
138+
Deprecated: PDOStatement::setFetchMode(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
139+
140+
Deprecated: PDOStatement::fetch(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
136141
myclass::unserialize('C:7:"myclass":19:{Data from serialize}')
137142
object(myclass)#%d (1) {
138143
["myprotected":protected]=>

ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize_simple.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ MySQLPDOTest::skip();
6969
print "done!\n";
7070
?>
7171
--EXPECTF--
72+
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
7273
Lets see what the Serializeable interface makes our object behave like...
7374
myclass::__construct('Called by script') - note that it must not be called when unserializing
7475
myclass::serialize()
@@ -77,14 +78,22 @@ object(myclass)#%d (0) {
7778
}
7879

7980
And now magic PDO using fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE)...
81+
82+
Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
8083
myclass::unserialize('Data fetched from DB to be given to unserialize()')
8184
object(myclass)#%d (0) {
8285
}
86+
87+
Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
8388
myclass::unserialize('Data fetched from DB to be given to unserialize()')
8489
object(myclass)#%d (0) {
8590
}
8691

8792
And now PDO using setFetchMode(PDO::FETCH:CLASS|PDO::FETCH_SERIALIZE) + fetch()...
93+
94+
Deprecated: PDOStatement::setFetchMode(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
95+
96+
Deprecated: PDOStatement::fetch(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
8897
myclass::unserialize('Data fetched from DB to be given to unserialize()')
8998
object(myclass)#%d (0) {
9099
}

0 commit comments

Comments
 (0)