Re: [Request][Discussion] Introduce interfaces PDOInterface and PDOStatementInterface
| From: | Andrew Nester | Date: | Mon, 31 Jul 2017 11:49:37 +0000 |
| Subject: | Re: [Request][Discussion] Introduce interfaces PDOInterface and PDOStatementInterface | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100134@lists.php.net to get a copy of this message | ||
That’s actually the thing that you can’t use PDO::ATTR_STATEMENT_CLASS with persistent PDO.
To make it possible to have persistent PDO with custom PDOStatement you should have:
1) custom
CustomPDO implements PDOInterface which will be somewhat proxy to PDO
instance
2) custom CustomPDOStatement implements PDOStatementInterface which will be returned
from CustomPDO::prepare and will have our additional logic + some stuff for persistence.
And in our userland code we can have type hints like someMethod(PDOInterface $pdo) or
someMethod(PDOStatementInterface $stmt)
I hope it explains a bit how interfaces could help here.
> On Jul 31, 2017, at 2:17 PM, Dan Ackroyd <danack@basereality.com> wrote:
>
> On 31 July 2017 at 08:21, Andrew Nester <newaltgroup@bk.ru> wrote:
>>
>> when we are using persistent PDO we can’t use PDO::ATTR_STATEMENT_CLASS and
>> return our custom PDOStatement class
>>
>> But just implementing PDOInterface and PDOStatementInterface will allow us to implement
>> this and have proper type hints in userland code.
>
> Are you sure having interfaces would change this?
>
> I would assume you can't use PDO::ATTR_STATEMENT_CLASS with persistent
> PDO due to a limitation of the implementation internal to PDO, rather
> than anything to do with what sub-classes what.
>
> Could you post a working example of being able to set
> PDO::ATTR_STATEMENT_CLASS with persistent PDO?
>
> cheers
> Dan