xref: /PHP-8.3/ext/pdo/tests/bug_52098.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #52098 Own PDOStatement implementation ignore __call()
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_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18@$db->exec("DROP TABLE test");
19$db->exec("CREATE TABLE test (x int)");
20$db->exec("INSERT INTO test VALUES (1)");
21
22class MyStatement extends PDOStatement
23{
24    public function __call($name, $arguments)
25    {
26        echo "Calling object method '$name'" . implode(', ', $arguments). "\n";
27    }
28}
29/*
30Test prepared statement with PDOStatement class.
31*/
32$derived = $db->prepare('SELECT * FROM test', array(PDO::ATTR_STATEMENT_CLASS=>array('MyStatement')));
33$derived->execute();
34$derived->foo();
35$derived->fetchAll();
36$derived = null;
37
38/*
39Test regular statement with PDOStatement class.
40*/
41$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyStatement'));
42$r =  $db->query('SELECT * FROM test');
43echo $r->bar();
44$r->fetchAll();
45$r = null;
46
47/*
48Test object instance of PDOStatement class.
49*/
50$obj = new MyStatement;
51echo $obj->lucky();
52
53$db->exec("DROP TABLE test");
54?>
55--EXPECT--
56Calling object method 'foo'
57Calling object method 'bar'
58Calling object method 'lucky'
59