Open
Description
Description
The following code:
<?php
declare(strict_types=1);
try
{
$pdo = new PDO('mysql:host=127.0.0.1', 'root', 'root');
$pdo->query('select x');
}
catch (\Throwable $e)
{
var_dump($e->getCode());
throw new \Exception($e->getMessage(), $e->getCode(), $e);
}
Resulted in this output:
string(5) "42S22"
PHP Fatal error: Uncaught TypeError: Exception::__construct(): Argument #2 ($code) must be of type int, string given in /mnt/d/projects/imi/imi-2.1/test.php:13
Stack trace:
#0 /mnt/d/projects/imi/imi-2.1/test.php(13): Exception->__construct()
#1 {main}
thrown in /mnt/d/projects/imi/imi-2.1/test.php on line 13
But I expected this output instead:
string(5) "42S22"
PHP Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'x' in 'field list' in /mnt/d/projects/imi/imi-2.1/test.php:8
Stack trace:
#0 /mnt/d/projects/imi/imi-2.1/test.php(8): PDO->query()
#1 {main}
Next Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'x' in 'field list' in /mnt/d/projects/imi/imi-2.1/test.php:13
Stack trace:
#0 {main}
thrown in /mnt/d/projects/imi/imi-2.1/test.php on line 13
Is it possible to change the return value of Throwable::getCode()
to int|string
?
php-src/Zend/zend_exceptions.stub.php
Line 12 in eb22f1a
PHP Version
8.0.21
Operating System
Ubuntu 20.04