On Monday, 2 June 2025 at 22:05, Rob Landers <rob@bottled.codes> wrote:

> No offense, but this feels like it was written by someone who doesn’t use 
> non-strict mode very often.

As yes, saying this to me, someone that is known to have said on stage, 
multiple times, during talks that
> The strict_types declare was a mistake.
Something I even reiterated 7 weeks ago at a Drupal conference. [1]
It would be nice that you don't make assumption about how I write PHP code, as 
I use weak and strict mode extensively while being annoyed with both modes 
constantly.
Moreover, even if one uses strict mode one must still know how weak mode 
behaves as closures/callables do not follow the typing mode in which they have 
been declared.

> The rules around coercion are pretty simple and well documented.

Considering I have given *multiple* talks about PHP's type system and type 
coercions rules, many people do *not* find them simple or intuitive and get 
bitten by them constantly.

> 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.

It would have been nice to showcase some of these shorthands rather than hiding 
them behind some sort of mystic as a counterargument.
I really would like to know in which cases you use non-boolean values as 
argument to boolean parameters.
People creating more subtle and worse bugs due to arbitrary casting is 
precisely why I want to unify the typing modes, so it's good to know that we 
think somewhat the same.

>> 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 know the reason why we coerce the string "0" to false.
But it is very atypical compared to every other programming language, so yes it 
is "weird".

> I don’t see the benefit of removing this implicit coercion.

The statement is noted.

Regards,
Gina P. Banyard

[1] https://youtu.be/85fgBcV3BuM?t=2832

Reply via email to