Re: Problem with loose typing
| From: | Matt M. | Date: | Fri, 17 Dec 2004 16:37:56 +0000 |
| Subject: | Re: Problem with loose typing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204592@lists.php.net to get a copy of this message | ||
> You would expect the while loop to go on forever just looking
> at the above code. However, what's happening is that when the
> empty string is getting returned due to $i being > 10, the while
> loop is resolving FALSE when $bob is set to the value of the
> empty string.
> Is there any way that I can force this not to happen? That the
> while loop resolves as FALSE only when the function actually
> returns a (boolean) FALSE value?
I think this should do it.
function test() {
static $i = 0;
$i++;
$retval = ( $i <= 10 ) ? $i : '';
return $retval;
}
while( ($bob = test()) !== false ) {
echo $bob . 'ECHO<br>';
}