RE: [PHP] PHP 5.2 array() == null
| From: | Robert Cummings | Date: | Tue, 15 May 2007 17:36:40 +0000 |
| Subject: | RE: [PHP] PHP 5.2 array() == null | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254983@lists.php.net to get a copy of this message | ||
On Tue, 2007-05-15 at 17:27 +0100, Edward Kay wrote:
> > -----Original Message-----
> > From: dominic.letz@berlin.de [mailto:dominic.letz@berlin.de]
> > Sent: 15 May 2007 16:48
> > To: php-general@lists.php.net
> > Subject: [PHP] PHP 5.2 array() == null
> >
> >
> > Hi people
> >
> > i was just curios to ask whether
> >
> > array() == null should always return true. and then why
> >
> > i'm testing this with php 5.2.2
> >
> > greetings
> >
> > dominic letz
> >
>
> According to Table Q.2 at
> http://www.php.net/manual/en/types.comparisons.php, array() ==
> NULL will
> always return TRUE.
>
> Remember == is a loose comparison. I think this is a result of the
> following:
>
> array() == FALSE is TRUE (because it's empty?)
Yes, being empty is why it is equivalent to boolean false. It makes it
simple and self explanatory to do code like the following:
<?php
if( $array )
{
// do something since it's not empty
}
else
{
// sorry nothing was found.
}
?>
This is preferable to using the count() function since no function
overhead is incurred.
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. |
`------------------------------------------------------------'