Maciek Sokolewicz wrote:
> ANR Daemon wrote:
>> 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.
> bullshit
s/bullshit/wrong
>
>>
>> <?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
>
> 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.
>
> - Tul
>
See differences here. It takes about 15 seconds to load, be patient.
http://www.cmsws.com/examples/php/testscripts/[EMAIL PROTECTED]/0001.php
Looks like the only thing that is different is the NULL results. In your case
above, it shouldn't matter. The values from the URL should never be a NULL
value. As far as I have ever seen, they are always strings. Be it empty or
not.
I added a speed test to the bottom of that page also. It shows the difference
between the two functions getting called 10,000 times.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php