monolog-mysql icon indicating copy to clipboard operation
monolog-mysql copied to clipboard

Dropping or getting around the PDO type hint in MySQLHandler::__construct()?

Open mehgcap opened this issue 4 years ago • 0 comments

I'm trying to use this in a project where database connection can remain open for a very long time. I've thus wrapped PDO in a ReconnectingPDO class, which catches the "connection has gone away" error, reconnects, then re-runs the query.

When I give a ReconnectingPDO instance to __construct(), I get the error that I've passed in an object of the wrong type. Fair enough, but I know it's the wrong type and want to proceed anyway. Since PHP doesn't check inheritance when using type hints (to my knowledge at least), is there any way to get around this restriction? I'm all for type hinting, and use it in everytyhing I write. In this case, though, it's causing a problem. Indeed, I had to go back and remove all my project's PDO type hints when I implemented ReconnectingPDO for this same reason.

mehgcap avatar Nov 27 '19 14:11 mehgcap