[php-src] master: ext/pdo: Avoid a duplicate warning for a rejected statement class

From: Date: Sun, 11 Oct 2026 12:32:17 +0000
Subject: [php-src] master: ext/pdo: Avoid a duplicate warning for a rejected statement class
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142183@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-10-11T08:13:28-04:00 Commit: https://github.com/php/php-src/commit/26e5bc454c9c507f714c3131cdb460eccad960ed Raw diff: https://github.com/php/php-src/commit/26e5bc454c9c507f714c3131cdb460eccad960ed.diff ext/pdo: Avoid a duplicate warning for a rejected statement class pdo_raise_impl_error() already reports the rejection of ATTR_STATEMENT_CLASS on a persistent connection, and the PDO_HANDLE_DBH_ERR() that followed emitted a second "General error" warning in ERRMODE_WARNING. Exception mode was unaffected, because the second call saw the pending exception. Closes GH-24204 Changed paths: A ext/pdo/tests/pdo_persistent_statement_class.phpt M NEWS M ext/pdo/pdo_dbh.c Diff: diff --git a/NEWS b/NEWS index 491e526d6b8f..aaed43baa2c8 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,10 @@ PHP NEWS . Fixed bug GH-24218 (Invalid opcode for count() of a literal array when SCCP is disabled). (Lazizbek Ergashev) +- PDO: + . Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a + persistent connection. (Ilia Alshanetsky) + - Phpdbg: . Fix wrong command names. (ndossche, Weilin Du) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index d3fcf6101249..a8be45e15588 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -900,7 +900,6 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) / pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances" ); - PDO_HANDLE_DBH_ERR(); return false; } if (Z_TYPE_P(value) != IS_ARRAY) { diff --git a/ext/pdo/tests/pdo_persistent_statement_class.phpt b/ext/pdo/tests/pdo_persistent_statement_class.phpt new file mode 100644 index 000000000000..0436fc9176fa --- /dev/null +++ b/ext/pdo/tests/pdo_persistent_statement_class.phpt @@ -0,0 +1,32 @@ +--TEST-- +PDO Common: Rejecting ATTR_STATEMENT_CLASS on a persistent connection reports one error +--EXTENSIONS-- +pdo +--SKIPIF-- +<?php +$dir = getenv('REDIR_TEST_DIR'); +if (false == $dir) die('skip no driver'); +require_once $dir . 'pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); +require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; + +putenv("PDOTEST_ATTR=" . serialize([PDO::ATTR_PERSISTENT => true])); +$db = PDOTest::factory(); + +var_dump($db->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class])); + +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +try { + $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class]); +} catch (PDOException $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; +} +?> +--EXPECTF-- +Warning: PDO::setAttribute(): SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances in %s on line %d +bool(false) +PDOException: SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances

« previous php.cvs (#142183) next »