Classes, error properties and PHP4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flycast
Forum Commoner
Posts: 37
Joined: Wed Jun 01, 2005 7:33 pm

Classes, error properties and PHP4

Post 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.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Classes, error properties and PHP4

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