waza-ari / monolog-mysql

MySQL Handler for Monolog, which allows to store log messages to a MySQL Table
MIT License
141 stars 85 forks source link

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

Closed mehgcap closed 1 year ago

mehgcap commented 4 years ago

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.

amacado commented 1 year ago

I think this adresses a very special case and since there's no movement since 2019 in this issue I'll tend to close it. Feel free to re-open it when you can provide a solution or idea to adress this feature request.