Hi Gina

Le jeu. 26 juin 2025 à 14:07, Gina P. Banyard <intern...@gpb.moe> a écrit :

> On Monday, 2 June 2025 at 17:11, Gina P. Banyard <intern...@gpb.moe>
> 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
>
> I have updated the RFC to version 0.2 that expands on it and addresses
> some of the counterarguments which were said during the discussion.
> RFC: https://wiki.php.net/rfc/deprecate-function-bool-type-juggling
>
> If there is no-follow up feedback, I will open the vote for it sometime
> next week.
>
>
Thanks for experimenting with this on
https://github.com/symfony/symfony/pull/60890/files

It's good to see that fitting this RFC requires a relatively small number
of lines to change even on a codebase like Symfony. We're not at 100% but
still nice.

Yet, it IS a big bang in terms of deprecations to fix that this will
trigger. Their number is super high, because these boolean
conversions happen on hotpath / in loops.

This reminds me of the mandatory "?" for arguments with null defaults: the
change made sense from a language design PoV, but the impact was, and still
is very high. It was and still is a very costly deprecation for the
community, and it's not over yet. That made me say at conferences that this
was maybe not a good idea...

Looking at the diff above, I think I can draw two sets of changes:
1. the ones that patch a cast-to-bool
2. the ones that patch a cast-from-bool

The latter, cast-from-bool, I think they're all useful improvements. While
most likely harmless in all the specific cases of the PR, doing e.g. an
strpos() on false feels hardly legit. I'm therefore sympathetic to making
these changes.

For cast-to-bool, I'm WAY less convinced. From the PR above, explicit casts
like "return (bool) preg_match(...)" on a method that returns a "bool" or "(
bool) ($this->loggedErrors & $type)" are a clear downgrade: it makes the
typing PHP just more verbose without any real benefit. That doesn't look
worth asking the whole ecosystem to fix those deprecations. It is
especially hard to see this as an improvement when comparing to using the
same expressions with e.g. the "if ()" operator, which doesn't need the
explicit cast (and shouldn't of course).

In the RFC, you write that its motivation is to allow making the bool type
equivalent to the true|false union. To do so you propose to make the bool
type always behave like in "strict" mode.

Personally, I'm moot about the motivation. I understand it, but it looks
inappropriate to push deprecations from this somewhat (IMHO) theoretical
angle. The added friction would need way stronger arguments to be justified
IMHO.

Would it be possible to trigger the deprecation only in the cast-from-bool
direction, and accept casts-to-bool as seamlessly as there are now? If yes,
then would it also be possible to make the true and false types have the
same behavior (aka non-strict in casts-to-bool direction - when not in
strict mode of course)? If yes to both questions, then that'd look like a
better outcome that'd still allow fulfilling your goal, while providing
maximum value to the community.

As is, the cost/benefit ratio doesn't make this RFC look worth it to me.

Last but not least, I'm not sure it's a good idea to rush this into 8.5.
This is a high-impact change. We should give some time to the discussion,
understand the impact and explore variants. Merging this in 8.6 would also
give a few more months for open-source projects to adapt to the change
(since many do run their CI with the master branch of PHP to spot changes
as early as possible.)

Cheers,
Nicolas

PS: I'm going AFK for the next ~7 days.

Reply via email to