On Sat, 2006-02-18 at 12:39, Rafael wrote:
> Actually, it doesn't have much sense that it creates a variable (or
> index), though it had sense why wouldn't be so easily detected, so I
> printed the array after the loops and there's no new keys. I think that
> if that was the case, it was definitely a bug that has been corrected
> (PHP 4.4.0)
> *Note: I guess that's because isset() is not a function, but a keyword
>
> That was very ilustrative Rob, thanks for the info (it's the kind of
> thing I shouldn't forget)
>
> Satyam wrote:
> [···]
> >> 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.
> >>
> [···]
> >
> > 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.
For the curious:
<?php
function myempty( &$value )
{
if( empty( $value ) )
{
return true;
}
return false;
}
$foo = array( 1 => 1 );
if( isset( $foo[2] ) )
{
echo 'WTF! :)';
}
print_r( $foo );
if( !empty( $foo[2] ) )
{
echo 'WTF! :)';
}
print_r( $foo );
if( !myempty( $foo[2] ) )
{
echo 'WTF! :)';
}
print_r( $foo );
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php