Re: php-general Digest 8 Jun 2000 05:53:04 -0000 Issue 48

From: Date: Thu, 08 Jun 2000 15:23:39 +0000
Subject: Re: php-general Digest 8 Jun 2000 05:53:04 -0000 Issue 48
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1306@lists.php.net to get a copy of this message
Yes, C expressions short-circuit. The ANSI doc discusses sequence points where the code before the sequence point is guaranteed to be executed and evaluated before any code after the sequence point is touched. It goes on to say that sequence points include (among other things): - The end of the first operand of the following operators: logical AND &&; logical OR ||; conditional ?; comma ,. All expressions using && and || are explicitly guaranteed to "short circuit" their evaluation once an answer to the expression can be determined. Having said all that, the answer to your question about whether php short circuits or not is in the manual: Short-circuited boolean evaluation In PHP 3.0 boolean evaluation is short-circuited. This means that in an expression like (1 || test_me()), the function test_me would not be executed since nothing can change the result of the expression after the 1. Bill >> if (isset($foo) && $foo=="bar" ) { >> do something; ... >From: "Matthew Kendall" <mdkendall@hotmail.com> >Date: Wed, 7 Jun 2000 10:53:01 -0700 >Subject: Re: [PHP-GENERAL] Evaluation of statements > >"Philipp Gasch¸tz" <philipp@gng.de> wrote... > >> which languages do you mean for example? >> C and Perl for example keep to the order in the statement >> (AFAIK at least...) > >Not true for C, I think. I don't know about Perl. > >My copy of the ANSI C spec says: > >"Except where noted, the order of evaluation of operands of individual >operators and subexpressions of individual expressions, and the order in >which side effects take place, is unspecified." > >Your particular compiler may happen to evaluate in the order you wrote, but >it does not have to. And its behaviour may change when you turn on the >optimiser, for example. --- Bill Rausch, Software Development, Unix, Mac, Windows Numerical Applications, Inc. 509-943-0861 bill@numerical.com

« previous php.general (#1306) next »