I cannot get a false value to return here. A true value returns fine. What am I missing?
if ((count($this->_brokenRulesCollection)) == 0) {
return true;
} else {
return false;
}
I cannot get a false value to return here. A true value returns fine. What am I missing?
if ((count($this->_brokenRulesCollection)) == 0) {
return true;
} else {
return false;
}
Well what is a $this->_brokenRulesCollection
? is it an array or an object? if an object does it implement Countable or Iterator?
The code can just return false
if the array $this->_brokenRulesCollection
is not empty.
If $this->_brokenRulesCollection
is not an array or an object with implemented Countable interface, then count($this->_brokenRulesCollection)
will returned 1.
In PHP, false
when converted to a string is an empty string, and true
converted to a string is "1".
Use var_dump
instead of echo
for debugging.
In conditional expressions (unless you use the type matching operators === or !==) any non-zero integer is equivalent to true, any non-zero length string is equivalent to true and conversely, zero or a blank string are false.
So
if ((count($this->_brokenRulesCollection)) == 0) {
return true;
} else {
return false;
}
Can be written as just:
return count($this->_brokenRulesCollection);
C.