Am 26.04.2022 um 15:16 schrieb Andreas Leathley <a.leath...@gmx.net>:
> On 26.04.22 14:47, Christian Schneider wrote:
>> There are two big reasons:
>> - BC: Checking for the truthiness of a value is very common and would 
>> require a lot of code changes.
>> - Some of us like the conciseness of "if ($foo) ...", see below
> 
> That would not be my target - in an if expression a lot more values are
> allowed anyway (arrays, objects, etc.), so this is not about determining
> truthiness, but actual conversions to a bool type, like a bool
> parameter, a bool return type or a bool property type.

I see, so as long as there are no bool type hints for function parameters 
everything would be the same.

This would lead to a minor asymmetry for
        $preserve = "yes";
        if ($preserve)  # Silently working, true
                array_slice($array, $offset, preserve_keys: $preserve));        
# Not working any more

I assume your solution would be to add an explicit cast to bool? i.e. something 
along the lines of
                array_slice($array, $offset, preserve_keys: (bool)$preserve));  
# Explicit cast to silence implicit conversion

I'm a bit worried about having to keep two different convert-to-bool rule sets 
in mind (implicit vs. explicit) and about the additional casts.

Regards,
- Chris

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

Reply via email to