Re: Re: Allowing is_* functions to accept multiple parameters
| From: | Chris London | Date: | Wed, 18 Sep 2013 13:57:44 +0000 |
| Subject: | Re: Re: Allowing is_* functions to accept multiple parameters | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69192@lists.php.net to get a copy of this message | ||
I like the naming convention of are_*. For me personally it isn't directly
intuitive that the multiple parameters of is_* would be compared with an &&
and not an ||.
On Wed, Sep 18, 2013 at 7:50 AM, Sean Coates <sean@seancoates.com> wrote:
> > i.e. is_null($a, $b, $c) would be the same as is_null($a) && is_null($b)
> > && is_null($c)
>
> Note that this would not be semantically equivalent in this form, even if
>
is_null() did accept multiple parameters, because of the
> short-circuiting
> with &&:
>
> <?php
>
> function are_null() {
> foreach (func_get_args() as $a) {
> if ($a !== null) {
> return false;
> }
> }
> return true;
> }
>
> function destroy_data() { echo "DESTROYING DATA\n"; }
>
> // old form: short-circuited; data is not destroyed
> if (is_null(null) && is_null(false) && is_null(destroy_data())) {
> echo "All null.\n";
> } else {
> echo "Not null.\n";
> }
>
> echo "----\n";
>
> // proposed form: no short-circuit; parameters are evaluated at call time
> and data is destroyed
> if (are_null(null, false, destroy_data())) {
> echo "Still null.\n";
> } else {
> echo "Still not null.\n";
> }
>
>