[php-src] Issue #12032: PDO::getAttribute() behaves differently than document
| From: | SakiTakamachi | Date: | Wed, 23 Aug 2023 05:26:30 +0000 |
| Subject: | [php-src] Issue #12032: PDO::getAttribute() behaves differently than document | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245230@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12032
Author: SakiTakamachi
### Description
The following code:
```php
<?php
// PDO::ERRMODE_SILENT
$pdo = new PDO('mysql:host=mysql;dbname=test;', 'root', '',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); // my env
var_dump($pdo->getAttribute(PDO::ATTR_TIMEOUT));
// PDO::ERRMODE_EXCEPTION
$pdo = new PDO('mysql:host=mysql;dbname=test;', 'root', ''); // my env
var_dump($pdo->getAttribute(PDO::ATTR_TIMEOUT));
```
Resulted in this output:
```
Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does
not support that attribute in /var/www/html/test/test_mysql.php on line 5
bool(false)
Fatal error: Uncaught PDOException: SQLSTATE[IM001]: Driver does not support this function: driver
does not support that attribute in /var/www/html/test/test_mysql.php:9
Stack trace:
#0 /var/www/html/test/test_mysql.php(9): PDO->getAttribute(2)
#1 {main}
thrown in /var/www/html/test/test_mysql.php on line 9
```
But I expected this output instead:
```
bool(null)
bool(null)
```
https://www.php.net/manual/en/pdo.getattribute.php#refsect1-pdo.getattribute-returnvalues
I suspect that the error/warning and returning false instead of null is probably just outdated
documentation.
Even so, it is strange that
warning is output with PDO::ERRMODE_SILENT.
I don't know if the documentation and the implementation need to be fixed, and if so, what
should be fixed, so I would like your opinion.
### PHP Version
PHP 8.1.22
### Operating System
_No response_