----- Original Message -----
From: "Robert Cummings" <robert@xxxxxxxxxxxxx>
To: "Rafael" <rsalazar@xxxxxxxxxxxx>
Cc: "PHP-General" <php-general@xxxxxxxxxxxxx>
Sent: Saturday, February 18, 2006 3:21 PM
Subject: Re: Re: "isset" or "array_key_exists"?
On Sat, 2006-02-18 at 04:56, Rafael wrote:
After a little test, although the results are not conclusive, I would
say that isset(), and also that array_key_exists() may even use isset()
(or similiar) internally as a first step -let's remember that isset()
only does a "fast search" and it returns FALSE if the value is NULL; on
the other hand, array_key_exists() returns TRUE even if the value is
NULL- I said this (as an hypotesis) because the difference in time when
the key exists and when it doesn't is quite big, sometimes about 10
times slower.
isset is a keyword in PHP
array_key_exists() is a function.
Keywords are much faster than functions due tot he overhead functions
occur for setting up the stack.
If you don't care about null values, use isset(). If you do, use
array_key_exists().
The reason isset() doesn't return true for null entries has been
described in the past. The official stance was that null is not a value.
Cheers,
Rob.
--
Accessing a non-existing element, doesn't create it? Thus, using isset to
evaluate whether an element exists creates it, though with a null value. If
you make a first pass on the array with isset, a second pass with
array_key_exists would give true for all of them though isset would give the
same results as in the first pass. I think this happened to me once when I
went through an array with isset or isempty or some such to make some
calculations and then on the second pass, when I printed it, I got lots of
empty cells that were created empty in the first pass.
Satyam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php