nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
502 stars 107 forks source link

Magic method __set return type of class ActiveRow is too strict #303

Closed feropeterko closed 1 month ago

feropeterko commented 9 months ago

Version: 3.2.0

Bug Description

New return type "never" of magic __set is too strict. It forces to throw an exception and disables the possibility to inherit \Nette\Database\Table\ActiveRow.

Steps To Reproduce

Inherit class \Nette\Database\Table\ActiveRow and override __set method.

Expected Behavior

Return standard type "void" and throw same exception. Do not force the exception with "never" return type.

ondrej-tuhacek commented 9 months ago

Exactly. I have a class that inherits ActiveRow and I'm now unable to use __set and __unset methods because of "never". Maybe "never" should be used only for "final" classes/methods that cannot be inherited from.

ondrej-tuhacek commented 2 months ago

Hi, any update on this? Has anyone who is struggling with this issue managed to overcome it somehow? Thanks.

feropeterko commented 2 months ago

Hi, I'm little disappointed from the support of this wide-used library. Unfortunatelly whole Nette forces data types in last years which is mostly correct but must not be forced like this. There are many users customizing functions for their needs.

Mostly you can use some reflection hacks (magic methods, ...) but not this time. Current change does not have a solution. I've been forced to drop the inheritance and make a wrapper. Perhaps you can find an inspiration in my solution https://github.com/varhall/dbino/blob/master/src/Model.php .

ondrej-tuhacek commented 1 month ago

Thank you @dg for changing type from never to void! But please consider changing it also for __unset method for consistency.