RE: [PHP-GENERAL] Evaluation of statements
| From: | Philipp Gaschütz | Date: | Wed, 07 Jun 2000 17:17:29 +0000 |
| Subject: | RE: [PHP-GENERAL] Evaluation of statements | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1234@lists.php.net to get a copy of this message | ||
huh?
which languages do you mean for example?
C and Perl for example keep to the order in the statement (AFAIK at
least...)
-p
> -----Original Message-----
> From: Matthew Kendall [mailto:mdkendall@hotmail.com]
> Sent: Mittwoch, 7. Juni 2000 18:59
> To: php-general@lists.php.net
> Subject: [PHP-GENERAL] Evaluation of statements
>
>
> In several places, including some tutorials at www.zend.com, I
> have seen
> example code that checks that a variable is set, then checks for a
> particular value, all in one statement, like this:
>
> if (isset($foo) && $foo=="bar" ) {
> do something;
> }
>
> Is this right? In other languages that I am familiar with the
> compiler (or
> interpreter) does not guarantee the order of execution of the two
> conditions. It is free to evaluate them in whatever order it likes.
> Furthermore, even if it does evaluate them in the order given,
> it is free to
> evaluate both of them before deciding whether the compound condition is
> true. This means that the second condition may be evaluated
> even if $foo is
> not set, which is an error (or at least a warning in PHP). It certainly
> defeats the intention of the isset() check.
>
> Does the PHP parser really guarantee order of execution, and
> guarantee to
> stop evaluating the expressions in a condition once the
> condition is false,
> or should the code really be written:
>
> if (isset($foo)) {
> if ($foo=="bar) {
> do something;
> }
> }
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
>