On Mon, 2009-08-10 at 15:40 -0300, Martin Scotta wrote:
> This "intelligence" is given by the laziness of the && operator.
> 
> $res = a() && b(); # if a() is false then b() does not evaluate
> $res = a() & b(); # b() evaluates no matter a()'s result
> 
> so, order matters.
> 
> On Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard <aball...@gmail.com> wrote:
> 
> > On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke<ralph_def...@yahoo.de>
> > wrote:
> > > this is not "intelligence" its just pure math. the '&&' says if BOTH
> > > expressions are true then the whole expression is true.
> > >
> > > so if the first one is false, the whole is false, why checking the next
> > one
> > > in the underlaying C it would be something like this
> > > {
> > > if ( expression == false ) return false;
> > > if ( expression == false) return false;
> > > return true;
> > > }
> > >
> > > ralph
> > > ralph_def...@yahoo.de
> >
> > That's logically correct, and while PHP does implement this
> > "short-circuit" logic, not all languages do. In that regard, I
> > appreciate what John meant by saying it makes it look "more
> > intelligent." Some languages evaluate each of the conditions to their
> > respective boolean results before evaluating the logical operators.
> >
> > Andrew
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
You get the same thing in bash. You call a bunch of commands to run in
series, but the next one only runs if it's predecessor was successful.
It's frequent to see this sort of command chain:

./configure && make && make install

Thanks,
Ash
http://www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to