>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.
There are already two different convert-to-bool rule sets for
array|object|resource|null, where they will be accepted in `if` but rejected
when
passed to a function taking a bool param:
```
$x = (object) ['a'=> 1];
if ($x) {
echo "if\n";
}
function takes_bool(bool $param) {}
takes_bool($x); // throws TypeError
```
https://3v4l.org/fCQFL
Adding string|float to that list doesn't seem to be that big of a difference
here.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php