AW: [PHP-DEV] Allowing is_* functions to accept multiple parameters

From: 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 [email protected] 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.



Thread (19 messages)

« previous php.internals (#69186) next »