On Tue, Jun 16, 2020 at 12:42 PM Dan Ackroyd <dan...@basereality.com> wrote:

> On Tue, 16 Jun 2020 at 11:32, Peter Bowyer <phpmailingli...@gmail.com>
> wrote:
> >
> > If it is, how can we change and improve the current situation?
> >
>
> Hi Peter,
>
> I think what I wrote earlier is still a good approach:
> https://externals.io/message/100773#100813
>
> > Taking it to a better solution is that the method sqliteCreateFunction
> > shouldn't exist on the PDO class, but instead on a PDOSqlite that
> > extends PDO.
> >
> > class PDOSqlite extends PDO {
> >      public function createFunction(...) {...}
> > }
> >
> > class PDO {
> >     public static function connect(string $dsn [, string $username [,
> >         string $password [, array $options ]]]) {
> >          if (connecting to SQLite DB) {
> >            return new PDOSqlite(...);
> >        }
> >.       // return new PDO(...);
> >    }
> > }
>
> Note, I haven't done the work to actually make sure that this plan is
> actually feasible, so it's not guaranteed to be the correct approach.
> But it still sounds sensible and would scale out to other custom
> methods for other connection types, and avoid any magic.
>
> If you (or anyone) have the time to work on this, that would be fantastic.
>

+1 on this approach. No magic, just normal inheritance.

For backwards-compatibility reasons, we'd presumably still have to retain
the ability to call those methods on the plain PDO object though :( But at
least there would be a way to use it in a sensible way in new code. In
particular this also allows you to write things like:

if ($pdo instanceof PDOSqlite) {
    $pdo->loadExtension(...);
}

Regards,
Nikita

Reply via email to