Yes, sure.

Good example has been provided in related issue in bug tracker.

Assume we are using persistent PDO and want to handle long running processes 
and add some logic when executing queries / connections (for instance logging).

It would require your custom classes deriving from PDO and PDOStatement where 
we add this additional logic.
According to documentation (http://php.net/manual/en/pdo.setattribute.php 
<http://php.net/manual/en/pdo.setattribute.php>) when we are using persistent 
PDO we can’t use PDO::ATTR_STATEMENT_CLASS and return our custom PDOStatement 
class instance from prepare method.

But just implementing PDOInterface and PDOStatementInterface will allow us to 
implement this and have proper type hints in userland code.

In addition, using interfaces is better from code architecture perspective 
(which is just my opinion and a bit arguable of course).

Thanks!




> On Jul 29, 2017, at 1:13 PM, Dan Ackroyd <dan...@basereality.com> wrote:
> 
> On 28 July 2017 at 07:40, Andrew Nester <newaltgr...@bk.ru> wrote:
>> Hello!
>> 
>> the only way to add some custom classes and behavior is to approach this is 
>> by subclassing PDO and PDOStatement.
> 
> 
> Please could you explicitly say when this is a problem, or what using
> an interface allows?
> 
> I can imagine possible scenarios, but the discussion would be clearer
> if you gave concrete examples.
> 
> cheers
> Dan

Reply via email to