xref: /PHP-8.2/ext/pdo_sqlite/tests/bug66033.phpt (revision 74859783)
1--TEST--
2Bug #66033 (Segmentation Fault when constructor of PDO statement throws an exception)
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7class DBStatement extends PDOStatement {
8    public $dbh;
9    protected function __construct($dbh) {
10        $this->dbh = $dbh;
11        throw new Exception("Blah");
12    }
13}
14
15$pdo = new PDO('sqlite::memory:', null, null);
16$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement',
17    array($pdo)));
18$pdo->exec("CREATE TABLE IF NOT EXISTS messages (
19    id INTEGER PRIMARY KEY,
20    title TEXT,
21    message TEXT,
22    time INTEGER)");
23
24try {
25    $pdoStatement = $pdo->query("select * from messages");
26} catch (Exception $e) {
27    var_dump($e->getMessage());
28}
29?>
30--EXPECT--
31string(4) "Blah"
32