On Mon, Jun 2, 2025, at 18:11, Gina P. Banyard wrote: > Hello internals, > > This is the first RFC out of a set of type system related RFCs I want to > propose for PHP 8.5. > It also used the recently enabled Markdown support on the wiki, so there > might be a few oddities. > > The RFC proposes to deprecate implicit type coercions to and from the bool > type for other scalar types. > This a "weak" mode change only, as when strict_types are enabled none of > these coercions can happen. > > Let me know what you think about it. > > RFC: https://wiki.php.net/rfc/deprecate-function-bool-type-juggling > > Best regards, > > Gina P. Banyard >
No offense, but this feels like it was written by someone who doesn’t use non-strict mode very often. The rules around coercion are pretty simple and well documented. Further, this makes a ton of shorthand nearly impossible — the manual casting to bool in strict mode is one of the most annoying casts someone has to do (and people screw up order of operations all the time leading to subtle bugs worse than coercion). Bringing this into all of php is probably not a good idea. > Type juggling of strings to bool is similarly error-prone. The strings "" and > "0" are converted to false, but "false", " ", and other strings which an > (int) cast converts to 0 are coerced to true. If I understand correctly, you are saying it is weird why the bytes 66 61 6C 73 65 are “true” and 30 is a special case, but not 20? If I remember my history correctly, 30 is special-cased because forms used to send “0” on checkboxes (if it sent it at all; it changed from decade to decade). I don’t see the benefit of removing this implicit coercion. — Rob