xref: /PHP-8.3/ext/pdo/tests/bug_44409.phpt (revision 858d0c09)
1--TEST--
2PDO Common: Bug #44409 (PDO::FETCH_SERIALIZE calls __construct())
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$db->exec("CREATE TABLE test (dat varchar(100))");
19$db->exec("INSERT INTO test (dat) VALUES ('Data from DB')");
20
21class bug44409 implements Serializable
22{
23    public function __construct()
24    {
25        printf("Method called: %s()\n", __METHOD__);
26    }
27
28    public function serialize()
29    {
30        return "any data from serizalize()";
31    }
32
33    public function unserialize($dat)
34    {
35        printf("Method called: %s(%s)\n", __METHOD__, var_export($dat, true));
36    }
37}
38
39$stmt = $db->query("SELECT * FROM test");
40
41print_r($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, "bug44409"));
42
43?>
44--EXPECTF--
45Deprecated: %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
46
47Deprecated: PDOStatement::fetchAll(): The PDO::FETCH_SERIALIZE mode is deprecated in %s on line %d
48Method called: bug44409::unserialize('Data from DB')
49Array
50(
51    [0] => bug44409 Object
52        (
53        )
54
55)
56