Bug #79769 [NEW]: PDO throws non-PDO exeptions
| From: | morozov at tut dot by | Date: | Thu, 02 Jul 2020 04:39:58 +0000 |
| Subject: | Bug #79769 [NEW]: PDO throws non-PDO exeptions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227767@lists.php.net to get a copy of this message | ||
From: morozov at tut dot by
Operating system: Linux
PHP version: 7.4.7
Package: PDO Core
Bug Type: Bug
Bug description:PDO throws non-PDO exeptions
Description:
------------
When interacting with a PDOStatement object, the consumer should be able
to expect all exceptions to be reported as PDOException. However, in
certain cases, the extension leaks its internal implementation details
and throws an Error.
Test script:
---------------
<?php
$conn = new PDO('sqlite:memory:');
$stmt = $conn->prepare('SELECT ?');
$stmt->bindValue(1, new DateTime());
try {
$stmt->bindValue(1, new DateTime());
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
try {
$stmt->execute([new DateTime()]);
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
// the above seems to be implemented just by casting the value to a
string since it behaves exactly as the following:
try {
(string) (new DateTime());
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
Expected result:
----------------
A PDOException is thrown instead of an Error
PDOException: Some message that says that this type cannot be bound to
the statement
Actual result:
--------------
Error: Object of class DateTime could not be converted to string
--
Edit bug report at https://bugs.php.net/bug.php?id=79769&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79769&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79769&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79769&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79769&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79769&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79769&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79769&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79769&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79769&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79769&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79769&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79769&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79769&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79769&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79769&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79769&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79769&r=mysqlcfg