Re: Re[2]: The 'at' sign (@) variable prefix
| From: | Maciek Sokolewicz | Date: | Thu, 09 Oct 2008 16:25:42 +0000 |
| Subject: | Re: Re[2]: The 'at' sign (@) variable prefix | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281648@lists.php.net to get a copy of this message | ||
ANR Daemon wrote:
Greetings, Ashley Sheridan. In reply to Your message dated Wednesday, October 8, 2008, 23:08:37,Well, filter_input does not exist in 5.1.6, and iset() does not work correctly with array keys in general. bullshitI'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.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
<?php $a = array ('test' => 1, 'hello' => NULL);The only case in which isset() returns false even though it IS set is when the value is null. That is the _only_ difference in functionality between isset and array_key_exists. Let's just ignore the fact that isset is about a dozen times faster than array_key_exists. But tell me, how often do you get a NULL value from $_GET or $_POST ? Because let me tell you, I don't see such a value...ever... And even if I did see it, it would not be a VALID value. - Tulvar_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