Skip to content

PDOException::getCode() returns string instead of int #12294

Closed as not planned
Closed as not planned
@8ctopus

Description

@8ctopus

Description

The following code:

<?php

declare(strict_types=1);

use PDO;
use PDOException;

try {
    $database = new PDO('sqlite::memory:', null, null, null);

    $query = $database->prepare('SELECT * FROM test2');
    $query->execute();
} catch (PDOException $exception) {
    $code = $exception->getCode();
    echo gettype($code);
}

Resulted in this output:

string

But I expected this output instead:

int

https://www.php.net/manual/en/class.pdoexception

final public Exception::getCode(): int

PHP Version

php 8.2.10

Operating System

alpine 3.18.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions