Page 1 of 1

Classes, error properties and PHP4

Posted: Wed Sep 09, 2009 7:17 am
by flycast
I know that PHP5 would work much better but I am trying to maintain PHP4 compatibility.

I have an object that has anywhere from none to a list of errors. The errors are stored in an array. I have to set the property $this->errors to be an empty array. The problem is testing for errors. It I test like this:
if($this->errors) then even an empty array seems to test TRUE. I have tried to force a change to the variable type or $errors but once I do the $errors = array() it seems to not want to change.

Any ideas? I want a simple true false test for if there are errors but I want to get the errors list if there are errors.

Re: Classes, error properties and PHP4

Posted: Wed Sep 09, 2009 8:24 am
by Weiry
have you tried using the empty() or count() functions?

Code: Select all

 
if(empty($this->array) || count($this->array)<1){
}
 
because i think your current statement simply check if the array exists. in which case, it will because its defined.