Re[2]: [PHP] Re[2]: The 'at' sign (@) variable prefix

From: Date: Thu, 09 Oct 2008 13:15:08 +0000
Subject: Re[2]: [PHP] Re[2]: The 'at' sign (@) variable prefix
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-281639@lists.php.net to get a copy of this message
Greetings, Ashley Sheridan. In reply to Your message dated Wednesday, October 8, 2008, 23:08:37, >> > If you're using it to deal with possible empty input data, you'd better do >> > it >> > explicitly enstead. >> > >> > Something like this: >> > >> > if(!array_key_exists('from_year', $_POST) >> > || !array_key_exists('from_month', $_POST) >> > || !array_key_exists('from_day', $_POST) >> > ) >> > { >> > throw new Exception('No start date given', 100); >> > } >> >> *cough* >> >> filter_input does this elegantly too ;) as does an isset() on the array index >> > I'm a fan of the isset() method for POST and GET variables, as usually > I'll still want to put something in the variables I'm assigning those > values to, rather than the NULL which gets returned by the @ prefix. Well, filter_input does not exist in 5.1.6, and iset() does not work correctly with array keys in general. <?php $a = array ('test' => 1, 'hello' => NULL); var_dump(isset($a['test'])); // TRUE var_dump(isset($a['foo'])); // FALSE var_dump(isset($a['hello'])); // FALSE // The key 'hello' equals NULL so is considered unset // If you want to check for NULL key values then try: var_dump(array_key_exists('hello', $a)); // TRUE ?> (c) http://php.net/isset -- Sincerely Yours, ANR Daemon <anrdaemon@freemail.ru>

« previous php.general (#281639) next »