> I probably brought this up in a previous thread, but I think it's worth
> considering again here, given recent changes to the RFC:
> 
> I think it would make more sense to introduce this as `function
> array_is_list(array $array): bool`. That is, a function that only accepts
> arrays in the first place and determines whether the given array is a list.
> 
> Your RFC does mention this possibility, but I think the argument it makes
> against it is not particularly strong, especially given the recent rename.
> The argument is that is_array_and_list($array) is shorter than writing out
> is_array($array) && array_is_list($array) -- that's still true, but with
> the new name, it's really not that much shorter anymore.
> 
> On the other hand, is_array($array) && array_is_list($array) cleanly
> separates out the two predicates. If we take into account the fact that in
> the vast majority of cases we will know a-priori that the input is an
> array, just not whether it is a list, making the function
> array_is_list($array) is both clearer and more concise.
> 
>    function foo(array $array) {
>        assert(array_is_list($array)); // Already know it's an array...
>    }
> 
>    if (is_array($value)) {
>        if (array_is_list($value)) { // Already know it's an array...
>            return serialize_as_list($value);
>        } else {
>            return serialize_as_dict($value);
>        }
>    }
> 
> Regards,
> Nikita

I like array_is_list(array $array): bool much better, too.

- Benjamin

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

Reply via email to