Bug #79769 [Opn->Nab]: PDO throws non-PDO exeptions
| From: | requinix@php.net | Date: | Thu, 02 Jul 2020 06:00:10 +0000 |
| Subject: | Bug #79769 [Opn->Nab]: PDO throws non-PDO exeptions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227768@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79769&edit=1
ID: 79769
Updated by: requinix@php.net
Reported by: morozov at tut dot by
Summary: PDO throws non-PDO exeptions
-Status: Open
+Status: Not a bug
Type: Bug
Package: PDO Core
Operating System: Linux
PHP Version: 7.4.7
Block user comment: N
Private report: N
New Comment:
The exception is not coming from PDO. It's coming from PHP. It happened when PDO tried to
convert the value to a string, and if your own library tried to do the same thing then PHP would
react the same way.
Previous Comments:
------------------------------------------------------------------------
[2020-07-02 04:39:57] morozov at tut dot by
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 this bug report at https://bugs.php.net/bug.php?id=79769&edit=1