Re: Re: Allowing is_* functions to accept multiple parameters
| From: | Sean Coates | Date: | Wed, 18 Sep 2013 13:50:30 +0000 |
| Subject: | Re: Re: Allowing is_* functions to accept multiple parameters | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69191@lists.php.net to get a copy of this message | ||
> 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";
}