Re: PHP boolean's



..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
.



Relevant Pages

  • Re: Emptying several arrays at once
    ... Have question if that is possible to empty a few arrays with one simple command? ... The desire to empty arrays is a bad sign. ... or the more comprehensive (but dangerous if other keys are being used) ... %addr if simply went out of scope. ...
    (perl.beginners)
  • Re: Null Range in Unconstrasined Array
    ... Well, arrays don't "point". ... no. Randy gave a reason why a compiler might want to ... has to allocate any space for My_Array above. ... Usually, empty arrays are not statically known to be empty, ...
    (comp.lang.ada)
  • Re: Empty constants
    ... EMPTY_ITERATOR, empty Object arrays, and a few things like empty ... as it plays more nicely with generics. ... For empty arrays, just new them up as needed. ...
    (comp.lang.java.programmer)
  • Re: Using split function for a csv file with blank line in between
    ... Test your arrstring to see if it is a valid array before attempting to work with its elements: ... It will work only with arrays that are set properly by the Split and a few other functions. ... fine until I've a file with empty lines in between and when I run the split ... My script is as below ...
    (microsoft.public.excel.programming)
  • Re: Emptying several arrays at once
    ... Have question if that is possible to empty a few arrays with one simple command? ... The desire to empty arrays is a bad sign. ... I think the straight forward way is more readable since I ... or the more comprehensive (but dangerous if other keys are being used) ...
    (perl.beginners)