On Tue, Nov 14, 2023 at 1:39 PM Andreas Hennings <andr...@dqxtech.net> wrote:
>
> Hello Robert,
>
> On Tue, 14 Nov 2023 at 11:09, Robert Landers <landers.rob...@gmail.com> wrote:
> >
> > Andreas,
> >
> > Just out of curiosity, what is the use case for this? I can't really
> > think of a practical case where strict checking is needed for these
> > functions. Usually, you have a really good idea of what is in the
> > arrays when writing the code and can handle any edge cases (like
> > nulls, empty strings, etc) long before you reach for these functions.
>
> I could ask the reverse question: When do you ever need a non-strict 
> comparison?
> I think in most modern php development, you would prefer the strict
> comparison version simply because it is more simple and predictable.
>
> But for real examples.
> One thing I remember is array_diff($arr, [null]) to remove NULL
> values, without removing empty strings.
> Perhaps we could say this is a special case that could be solved in
> other ways, because we only remove one value.
>
> Another thing is when writing reusable general-purpose functions that
> should work for all arrays.
> The caller might know the types of the array values, but the developer
> of the reusable function does not.
>
> Another problem is if your arrays contain anything that is not
> stringable. like objects and arrays.
>
> Maybe I will remember other examples that are more practical.
>
> Btw, as a general note on strict vs non-strict:
> In some cases you want a "half strict" comparison, where '5' equals 5,
> but true does NOT equal '1'.
> But for now I am happy to focus on pure strict comparison.
>
> Andreas
>
>
> >
> > Robert Landers
> > Software Engineer
> > Utrecht NL
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: https://www.php.net/unsub.php
> >

Hello Andreas,

> Another problem is if your arrays contain anything that is not
> stringable. like objects and arrays.

array_udiff() comes to mind here, is there a reason that doesn't work?
It would allow you to 'half-equals' things as well, if you want.

> I could ask the reverse question: When do you ever need a non-strict 
> comparison?

You actually answer your own question :)

> where '5' equals 5,

One of the most beautiful things about PHP is that null == 0 == false,
or '5' == 5 == 5.0, or 1 == true == 'hello world', which is so
incredibly handy in web-dev that to ignore it is inviting bugs.
Headers may or may not be set, form values may or may not be set, JSON
documents may or may not be missing keys/values, etc. How everything
is coerced is extremely well documented and very obvious after working
with PHP for a while.

I'm reminded of this principle in PHP, quite often:

> Be conservative in what you do, be liberal in what you accept from others.

Robert Landers
Software Engineer
Utrecht NL

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to