On Tue, Jun 18, 2024 at 9:18 PM Claude Pache <claude.pa...@gmail.com> wrote:
>
> Hi,
>
> > One thing is clear is that "strict types" may be a bit of poor word
> > choice and gives people a false sense of security that it is "safe" or
> > "more correct" when this obviously isn't true. Thus, I'd like to
> > propose, for PHP 9, simply renaming it from strict_types to
> > scalar_type_coercion and flipping the value:
> >
> > <?php declare(strict_types=1);
> >
> > to
> >
> > <?php declare(scalar_type_coercion=0);
>
> This not better. Even with `declare(scalar_type_coercion=0)`, there will be 
> scalar type conversions between string and int/float when you add numeric 
> strings or when you concatenate a string with an int.

This is a really good point and worth thinking about. I kinda like
Rowan's suggestion of scalar_args with a usage of string values
instead of integers.

>
> IMO, the real problem with the current name, is that there is no clue that 
> this directive is specifically about arguments and return values in 
> function/method calls.

Yes. This is kinda what I was hoping to address, but like you said,
the name I suggested didn't really capture the semantics either. :D

>
> > Perhaps it might even be worth adding a secondary vote to flip the
> > default, such that if you want to "old" behavior back:
> >
> > <?php declare(scalar_type_coercion=1);
>
> That would force to edit thousands of files, ... for exactly zero gain. Have 
> you heard about the Red Queen's race?

This is a pretty simple search-and-replace, so I don't think it would
be hard to update. That being said, there still needs to be a
deprecation strategy that makes sense. As to it being "zero gain,"
words have meaning and choosing the right ones (even if it is years
later) can sometimes be completely worth it and even have monetary
gains.

>
> Moreover, there are many places where it is not possible to add such a 
> declaration. For instance, `array_map(...)`, etc., always use 
> `strict_types=0` when invoking the callback. Changing that would also be a 
> big BC break.
>
> —Claude


Robert Landers
Software Engineer
Utrecht NL

Reply via email to