Larry Garfield wrote:

> "Create all DB sub-classes?" - I'd say they all should have subclasses, even
> if empty.  It's more consistent* that way, and you can then also rely on
> instanceof giving you useful information rather than "well, it's not one of
> the special ones, so beyond that, NFI."

You can get the database type through $db->getAttribute(PDO::ATTR_DRIVER_NAME);

On Tue, 21 Jun 2022 at 15:39, Ben Ramsey <ram...@php.net> wrote:
>
> Is there a reason we shouldn't go ahead and add subclasses for all
database connection types,

YAGNI, and I'm lazy. But mostly, I don't think adding them now
actually helps achieve anything.

Being able to check if the class has specialised methods is useful:

if ($pdo instanceof PDOSqlite) {
    $pdo->loadExtension(...);
    // do fun stuff with extension here.
}


But for the classes that have no specialised method:

if ($pdo instanceof PDOMysql) {
   // What would be of utility here?
}

cheers
Dan
Ack

* How to value being consistent is an aesthetic choice that many other
programmers disagree with me on; "The fundamental guiding force to
bear in mind is whether something is useful or not. Consistency might
satisfy a personal desire for order and simplicity, but most of the
time just having things be consistent is a lower priority than making
choices that are useful." or in this case, less code to write and
maintain.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to