Aura.Sql icon indicating copy to clipboard operation
Aura.Sql copied to clipboard

Support for PHP 8.4

Open srjlewis opened this issue 4 months ago • 9 comments

Hi

I am doing some eairly testing with PHP 8.4

I have found a conflict within the library

Fatal error: Cannot make static method PDO::connect() non static in class Aura\Sql\AbstractExtendedPdo in /some-project-dir/vendor/aura/sql/src/AbstractExtendedPdo.php on line 161

It is a result of a accepted PHP RFC https://wiki.php.net/rfc/pdo_driver_specific_subclasses which introduces a static connect method PDO::connect() as shown in the above method.

Here is lavavel's fix within there library https://github.com/laravel/framework/pull/52538/files

It looks like ExtendedPdoInterface::connect() would need renaming to somthing along the lines of ExtendedPdoInterface::autoConnect() and throughout the rest of the library.

I would then think ExtendedPdo:autoConnect() would looke somthing like.

class ExtendedPdo extends AbstractExtendedPdo
{
    public function autoConnect(): void
    {
        if ($this->pdo) {
            return;
        }

        // connect
        $this->profiler->start(__FUNCTION__);
        list($dsn, $username, $password, $options, $queries) = $this->args;
        if(version_compare(phpversion(), '8.4.0', '<')) {
            $this->pdo = new PDO($dsn, $username, $password, $options);
        } else {
             $this->pdo = PDO::connect($dsn, $username, $password, $options);
        }
        $this->profiler->finish();

        // connection-time queries
        foreach ($queries as $query) {
            $this->exec($query);
        }
    }
}

This would need to be a new majer version due to the big BC break ExtendedPdoInterface::connect() being public.

I can create a MR for this if needed.

srjlewis avatar Oct 03 '24 10:10 srjlewis