PHP 4.0 Bug #4037: improper parsing of logical statements
| From: | oded at geek dot co dot il | Date: | Tue, 04 Apr 2000 22:52:19 +0000 |
| Subject: | PHP 4.0 Bug #4037: improper parsing of logical statements | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-17613@lists.php.net to get a copy of this message | ||
From: oded@geek.co.il
Operating system: Linux 2.2
PHP version: 4.0 Release Candidate 1
PHP Bug Type: Scripting Engine problem
Bug description: improper parsing of logical statements
it seems that PHP4RC1 doesn't evaluate logical statements in the same way as PHP3 did . this
causes some errors which (at first glance) looked to me as MySQL driver errors where a valid SQL
statement, when implemented in a code similar to this :
if ($result = mysql_query($query) && $row = mysql_fetch_array($result)) {
would return a mysql warning : "Supplied argument is not a valid MySQL result ersource" on
the mysql_fetch_array command.
I think this happens because PHP4 doesn't evaluate the mysql_query part before the
mysql_fetch_array part, which results in the fact that the $result variable isn't set in time
for the mysql_fetch_array command.
this behavior could be well demonstrated by the two following pieces of code :
1)
$t = 1;
if ( $t = $t + 1 && $w = $t + 1 ) {
echo "right ! t: $t w: $w";
} else {
echo "wrong! t: $t w : $w";
}
2)
$t = 1;
if ( ($t = $t + 1) && $w = $t + 1 ) {
echo "right ! t: $t w: $w";
} else {
echo "wrong! t: $t w : $w";
}
which although they look semanticly the same give different results.