Unexpected behavior of int vs bool

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I was very surprised to find the following while debugging.

// Consider this simple function.
function loop($n)
    for ($i = 10; $i >= $n; $i--) echo "Loop $i\n";

// I accidentally passed False (or NULL) to code like that.

This results in an infinite loop!

This is not a bug. It is working exactly as documented.
And I learned not to assume type conversions work as expected.

Re: Unexpected behavior of int vs bool

On 08/29/2010 09:29 PM, ljb wrote:
Quoted text here. Click to load it

Yes, you should read about comparing different types and how implicit
typecasting works.

Site Timeline