Commit 5d57dd6140a for php
commit 5d57dd6140a874204e6a93719fccf3a201500507
Author: 武田 憲太郎 <takeda@youmind.jp>
Date: Sat Sep 26 02:15:34 2026 +0000
ext/pdo_pgsql: Fix crash when a persistent connection fails
The shutdown function tried to reset the session state even when the
connection had failed.
Regression from GH-20572.
Close GH-23922
diff --git a/NEWS b/NEWS
index 40bc06f89e2..5dadee43b6c 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,9 @@ PHP NEWS
. Fixed pcntl_signal_dispatch() dropping the signals queued behind a handler
that throws. (nicolas-grekas)
+- PDO_PGSQL:
+ . Fixed crash when a persistent connection fails. (KentarouTakeda)
+
24 Sep 2026, PHP 8.6.0RC2
- Core:
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 358ac81eb88..5aa95cdccaf 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1597,7 +1597,7 @@ static void pdo_dbh_free_storage(zend_object *std)
dbh->in_txn = false;
}
- if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) {
+ if (dbh->is_persistent && dbh->driver_data && dbh->methods && dbh->methods->persistent_shutdown) {
dbh->methods->persistent_shutdown(dbh);
}
zend_object_std_dtor(std);
diff --git a/ext/pdo_pgsql/tests/persistent_connection_failure.phpt b/ext/pdo_pgsql/tests/persistent_connection_failure.phpt
new file mode 100644
index 00000000000..7be690ae05a
--- /dev/null
+++ b/ext/pdo_pgsql/tests/persistent_connection_failure.phpt
@@ -0,0 +1,21 @@
+--TEST--
+PDO PgSQL failed persistent connection does not crash on object destruction
+--EXTENSIONS--
+pdo_pgsql
+--FILE--
+<?php
+
+try {
+ new Pdo\Pgsql('pgsql:host=/nonexistent', options: [
+ PDO::ATTR_PERSISTENT => true,
+ ]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), PHP_EOL;
+}
+
+echo "Failed connection object destroyed without crash\n";
+
+?>
+--EXPECTF--
+PDOException: SQLSTATE[08006] [7] %a
+Failed connection object destroyed without crash