Skip to content

Fix PHP 8.4 compatibility: Replace get_class() check with instanceof for PDO connections #14

@xkrdudrlf

Description

@xkrdudrlf

Description

Fixes compatibility issue with PHP 8.4 where PDO driver-specific subclasses are returned instead of the base PDO class.

Problem

In PHP 8.4, the PDO extension now returns driver-specific subclasses (e.g., Pdo\Pgsql, Pdo\Mysql) instead of instances of the base PDO class. This breaks the current check on line 135 in koolreport\datasources\PdoDataSource class:

// line 135, koolreport\datasources\PdoDataSource
        if (is_object($connection) && get_class($connection) === \PDO::class) {
            $this->connection = $connection;
        } else if (isset(PdoDataSource::$connections[$key])) {

Solution

Replace strict get_class() comparison with instanceof operator to support PHP 8.4's new PDO driver-specific subclasses (Pdo\Pgsql, Pdo\Mysql, etc.).

The previous check get_class($connection) === \PDO::class fails in PHP 8.4 because connections now return driver-specific subclass names instead of the base PDO class name.

Using instanceof maintains backward compatibility with older PHP versions while properly handling the new subclass inheritance in PHP 8.4+.

Also removes redundant is_object() check since instanceof already handles non-object values correctly.

// line 135, koolreport\datasources\PdoDataSource
        if ($connection instanceof \PDO) {
            $this->connection = $connection;
        } else if (isset(PdoDataSource::$connections[$key])) {

Ref: https://www.php.net/releases/8.4/en.php#pdo_driver_specific_subclasses

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions