Re: repetition of tedious references
| From: | Olav Mørkrid | Date: | Wed, 18 Jul 2007 14:19:07 +0000 |
| Subject: | Re: repetition of tedious references | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-259117@lists.php.net to get a copy of this message | ||
if the string is not set, you will get an "undefined index" error when
calling isused(). that's just the problem. you can't reference an
unset string without doing isset first, so putting isset inside the
function is simply too late.
On 18/07/07, C.R.Vegelin <cr.vegelin@hetnet.nl> wrote:
Hi OLav, what about this ? $language = isused($_SERVER["HTTP_ACCEPT_LANGUAGE"]); echo "language is " . $language; function isused($variable) { return isset($variable) && $variable != "" ? $variable : "*"; } HTH, Cor ----- Original Message ----- From: "Olav Mørkrid" <olav.morkrid@gmail.com> To: "PHP General List" <php-general@lists.php.net> Sent: Wednesday, July 18, 2007 1:24 PM Subject: [PHP] repetition of tedious references consider the following statement: $language = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && $_SERVER["HTTP_ACCEPT_LANGUAGE"] != "" ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : "*"; when using strings in arrays that may be non-existing or empty, you have to repeat the reference *three* times, which gets excessive and unreadable. is there any way to only have to write $_SERVER["HTTP_ACCEPT_LANGUAGE"] only once? i know it's possible to supress "is not set" with @, but that just seems wrong in case there really is an error in the statement. i love php, but this is one of my pet peeves. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php