PHP is a loosely-typed language, meaning that the empty string '' will
evaluate to false unless you do strict comparisons (=== and !==). For
example:
$test = FALSE;
if ('' != $test) {
// this executes because of loose typing
}
if ('' !== $test) {
// this doesn't execute because of strict comparison
}
When testing function return values that may return a number or FALSE, it is
best to use strict comparisons:
while(false !== ($attribute = $result->fetch_assoc())) {
...
}
--
*Hector Virgen*
Sr. Web Developer
Walt Disney Parks and Resorts Online
http://www.virgentech.com
On Thu, Aug 26, 2010 at 10:54 AM, Daniel Latter <[email protected]>wrote:
> Hi All,
>
> forgive me for the simplistic question but looking through ZF source I
> see if statements structured like so:
>
> if ('' === $value) {
> ..
> }
>
> is this just to protect against $value being empty?
>
> Consequently, would I be better doing this:
>
> while(false != ($attribute = $result->fetch_assoc())) {
> ...
> }
>
> instead of:
>
> while($attribute = $result->fetch_assoc()) {
> ..
> }
>
> TIA
>
> Dan
>