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.
Classes, error properties and PHP4
Moderator: General Moderators
Re: Classes, error properties and PHP4
have you tried using the empty() or count() functions?
because i think your current statement simply check if the array exists. in which case, it will because its defined.
Code: Select all
if(empty($this->array) || count($this->array)<1){
}