Re: PHP boolean's
- From: Michael Fesser <netizen@xxxxxx>
- Date: Sat, 31 May 2008 14:45:02 +0200
..oO(Rik Wasmus)
One could even argue using if(count($someArray) == 0) is better, as
empty() will not only work for arrays , but for a whole list of empty
values ('',0,null, etc.). Using the count function does immediatly issue
an error (non-fatal) when $someArray is not an array, making it more easy
to track bugs and errors. That being, said, I usually do use empty()
though :).
ACK
The only annoying thing (IMHO) about empty() is that it only works on
variables, but sometimes I want to directly check a function result.
So I had to write a little helper function:
function isEmpty($var) {
return empty($var);
}
Now I can do things like
if (isEmpty(getSomething())) {
...
}
where the normal empty() would complain.
Micha
.
- References:
- PHP boolean's
- From: Michael Sharman
- Re: PHP boolean's
- From: petersprc
- Re: PHP boolean's
- From: Michael Sharman
- Re: PHP boolean's
- From: Michael Fesser
- Re: PHP boolean's
- From: Rik Wasmus
- PHP boolean's
- Prev by Date: Re: PHP boolean's
- Next by Date: Re: using fopen() in write mode is failing
- Previous by thread: Re: PHP boolean's
- Next by thread: able to upload 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
- Index(es):
Relevant Pages
|