Re: If 1 IF fails, do the rest anyway...

From: Date: Thu, 13 Mar 2003 21:27:01 +0000
Subject: Re: If 1 IF fails, do the rest anyway...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139602@lists.php.net to get a copy of this message
At 22:13 13.03.2003, Liam Gibbs said: --------------------[snip]-------------------- >I know that in a case like this > >if((test1) && (test2) && (test3)) { > ... >} > >if test1 fails, dear PHP won't bother doing test2 and 3. Am I correct? Is >there a syntax that will make it carry on with test2 and 3 anyway, >regardless of how test1 came out? --------------------[snip]-------------------- The rule for AND chains is: - evaluate the expressions from left to right - stop AND DON'T RUN THE IF-BLOCK at the first expression evaluating to false The rule for OR chains is: - evaluate the expressions from left to right - stop AND RUN THE IF-BLOCK at the first expression evaluating to true This feature is inherent to all (well, most at least) languages - so be aware of side effects (or no side effects occurring) with such constructs. To allow _all_ expressions to be evaluated you need to run all 3 by themselves, later comparing the results: $x1 = test1(); $x2 = test2(); $x3 = test3(); if ($x1 && $x2 && $x3) ... -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#139602) next »