|
Posted by Steve on 01/07/08 16:54
"Michael Fesser" <netizen@gmx.de> wrote in message
news:pmk4o3trg1johm5rcaiho04qaos5kbd5rg@4ax.com...
> .oO(jodleren)
>
>>How do IF behave in php?
>>
>>Say,
>>if( $goahead && copy($somefile1, $somefile2) )
>> echo "hello world";
>>
>>What if $goahead is false, will the if the fall, or test all of the
>>statements?
>
> PHP uses lazy evaluation. As soon as the result is known, the evaluation
> stops. Because of this behaviour you can write things like
more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?
most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.
cheers.
[Back to original message]
|