note 46744 modified in function.func-get-arg by danbrown
| From: | danbrown@php.net | Date: | Sat, 19 Jul 2008 21:33:56 +0000 |
| Subject: | note 46744 modified in function.func-get-arg by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141759@lists.php.net to get a copy of this message | ||
I've always wants a deferment or cascade operator so that I could use this expression:
$a = $b ## $c ## $d;
and everything to the right of the assignment operator would evaluate to the left-most value that is
not null. It is essentially a collapsed version of this:
<?php
if ($b) {
$a=$b;
} else {
if($c) {
$a=$c;
} else {
if ($d) {
$a = $d;
} else {
$a = null;
}
}
}
?>
In leiu of this, I'm trying to make a function that takes a variable number of arguments and
returns the first that is not null. I wan't to use this on some large-ish arrays, so I'd
like to pass these by reference. However, call-time reference passing is disabled (and should be,
imo) in newer versions of PHP. I'd like suggestions on how to pass both references and values
to this function.
The only solution I can think of is setting variables to the reference of the array first. e.g.
$a = array( ... );
$b = 0;
$c = &a;
first_not_null($a, $b);
Does anyone know a better solution?
--was--
I've always wants a deferment or cascade operator so that I could use this expression:
$a = $b ## $c ## $d;
and everything to the right of the assignment operator would evaluate to the left-most value that is
not null. It is essentially a collapsed version of this:
if ($b) {
$a=$b;
} else {
if($c) {
$a=$c;
} else {
if ($d) {
$a = $d;
} else {
$a = null;
}
}
}
In leiu of this, I'm trying to make a function that takes a variable number of arguments and
returns the first that is not null. I wan't to use this on some large-ish arrays, so I'd
like to pass these by reference. However, call-time reference passing is disabled (and should be,
imo) in newer versions of PHP. I'd like suggestions on how to pass both references and values
to this function.
The only solution I can think of is setting variables to the reference of the array first. e.g.
$a = array( ... );
$b = 0;
$c = &a;
first_not_null($a, $b);
Does anyone know a better solution?
http://php.net/manual/en/function.func-get-arg.php