Actually they are not the same, as this code illistrates: $foo = array( 1, 2, 3, 4, 5 ); unset( $foo[1] );
foreach( $foo as $key => $value ) { echo $foo.' -> '.$value."\n"; } Output: 0 -> 1 2 -> 3 3 -> 4 4 -> 5 in contrast to: $foo = array( 1, 2, 3, 4, 5 ); $foo[2] = null; foreach( $foo as $key => $value ) { echo $key.' -> '.$value."\n"; } Output: 0 -> 1 1 -> 2 2 -> 3 -> 4 4 -> 5 As you can see the entry is not null, it is completely missing. And while you might think that variable_exists($foo) is a synonym for in_array in_array('foo', array_keys(get_defined_vars())) I would strongly argue otherwise. Maybe you should see how that whole evaluation works. Retrieving the keys of an array with say 100 entries would require the copying of 100 key values to zvalues, and then returning a new array. This new array would subsequently be searched for the value, which of course is always slower than looking for the key itself. Whereas variable_exists() would perform a single lookup on the key and not require the copying of keys to zvalues. One is MUCH more efficient than the other. Cheers, Rob. On Sat, 2003-08-16 at 17:51, Stefan Walk wrote: > On Sat, Aug 16, 2003 at 02:42:17PM -0700, Lars Torben Wilson wrote: > > But the change would make it more consistent, by recognizing that a > > variable with a NULL value is still defined. Pretending that $foo = > > null and unset($foo) are the same thing is quite inconsistent and > > confusing for many, when there are ways (i.e. get_defined_vars()) to > > prove that they are not the same. > > You can see that they are meant to be the same by doing > $foo = (unset)$foo; ... $foo is null afterwards :) > Anyway, > variable_exists($foo) > is just a synonym for > in_array('foo', array_keys(get_defined_vars())) > which is not too much trouble to type IMO. *shrug* -- .---------------------------------------------. | Worlds of Carnage - http://www.wocmud.org | :---------------------------------------------: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul. | `---------------------------------------------' -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php