For an operation as complicated as "use the first variable
that exists"
I would be most comfortable with:$d = first-existing: $a, $b, $c;
That's a horrible syntax, but a fantastic name for a language construct to do the job. Even better might be (something like) first_isset($a, $b, $c) which tells you precisely what's happening: you get the first value that passes the isset() test.
I also find the ?? / ??= suggestion very attractive - it would have been my suggestion for a suitable operator.
Cheers!
Mike
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
What about a similar construct for checking truth? eg,
$foo = first_true($bar, $baz, $bang);
returns the value of the first variable that passes the if(isset($var)
&& !empty($var)) test.
For an operation as complicated as "use the first variable
that exists"
I would be most comfortable with:$d = first-existing: $a, $b, $c;
That's a horrible syntax, but a fantastic name for a language construct to do the job. Even better might be (something like) first_isset($a, $b, $c) which tells you precisely what's happening: you get the first value that passes the isset() test.
I also find the ?? / ??= suggestion very attractive - it would have been my suggestion for a suitable operator.
Cheers!
Mike
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
--
--