xref: /PHP-8.2/ext/pdo/tests/bug_44159.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #44159 (Crash: $pdo->setAttribute(PDO::STATEMENT_ATTR_CLASS, NULL))
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$pdo = PDOTest::factory();
17$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
18
19$attrs = array(PDO::ATTR_STATEMENT_CLASS, PDO::ATTR_STRINGIFY_FETCHES);
20
21foreach ($attrs as $attr) {
22    try {
23        var_dump($pdo->setAttribute($attr, NULL));
24    } catch (\Error $e) {
25        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
26    }
27    try {
28        var_dump($pdo->setAttribute($attr, 1));
29    } catch (\Error $e) {
30        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
31    }
32    try {
33        var_dump($pdo->setAttribute($attr, 'nonsense'));
34    } catch (\Error $e) {
35        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
36    }
37}
38
39@unlink(__DIR__."/foo.db");
40
41?>
42--EXPECT--
43TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, null given
44TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, int given
45TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, string given
46TypeError: Attribute value must be of type bool for selected attribute, null given
47bool(true)
48TypeError: Attribute value must be of type bool for selected attribute, string given
49