AW: [PHP-DEV] Allowing is_* functions to accept multiple parameters
| From: | Frank Liepert | Date: | Wed, 18 Sep 2013 12:21:08 +0000 |
| Subject: | AW: [PHP-DEV] Allowing is_* functions to accept multiple parameters | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69186@lists.php.net to get a copy of this message | ||
> 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.