AW: [PHP-DEV] Allowing is_* functions to accept multiple parameters
> function doStuffWithNumbers(...$numbers) {
> if (!is_int(...$numbers)) {
> throw new InvalidArgumentException('blah');
> ...
>
> Thoughts?
Returning bool in this case will make it impossible to respond with a
meaningful error message. Which of the provided arguments !is_int()?
Instead, I would go with f.Ex.:
$numbers = array(...$numbers);
$result = array_filter($numbers, "is_int")
and compare the arrays. Since the array keys are preserved, it's easy to
find out, which argument !is_int().
Finally, the imho best solution would still be introducing optional scalar
type hinting. But that is another topic and shouldn't be discussed here.
Thread (19 messages)