On Sat, Jan 16, 2021 at 6:07 PM Christian Schneider <cschn...@cschneid.com> wrote:
> While testing the migration of our site to PHP 8 we noticed the BC break > in internal functions like round() for parameter type errors: > round("foo") used to (silently, without warning) cast to float and return > 0 where as now it throws a TypeError: round(): > https://3v4l.org/pU0LD > > The RFC at > https://wiki.php.net/rfc/consistent_type_errors#backward_incompatible_changes > <https://wiki.php.net/rfc/consistent_type_errors> states > > Backward Incompatible Changes > > > > A TypeError will be thrown instead of a warning if incorrectly typed > parameters are passed to a function, which is a backwards incompatible > change. > > But that is not the whole truth because it suggests that there was a > warning in 7.4 which is not the case for functions like round() and > possibly many more. > > This makes the BC break much more impactful as there is no easy way to > know if old code will suddenly abort with an exception whereas it used to > run without any warning. > > Is there any way of knowing what functions are affected by this? > > This might be a blocker for people to migrate to PHP 8, should there be a > way to have a warning-instead-of-exception stage added to PHP 8 even though > there first versions were already released to help people migrate? > > Or did I miss something? > This is the interaction of two changes. The RFC does exactly what it says, and promotes certain warnings to Error exceptions. At the same time, PHP 8 moved some function implementations to use standardized parameter handling. These two changes in conjunction can, in rare cases, conspire to produce an Error where previously no warning was thrown. round() is an example of where this happened. I don't think there's a comprehensive list of edge cases where something like this has occurred. It would certainly be useful if any cases that are found make their way into the manual. Relevant changelog entries are being added to functions as their methodsynopses are updated for PHP 8 -- this is ongoing work and has not reached the round() function yet. (You can find all changelog entries for PHP 8.0.0 that are currently available on https://www.php.net/manual/en/doc.changelog.php, though this has more information than is probably relevant to you. Many of those changes aren't backwards-incompatible, just document previous behavior.) Regards, Nikita