#29758 [Opn->Bgs]: 'and' produces erroneous results
| From: | derick@php.net | Date: | Thu, 19 Aug 2004 14:33:21 +0000 |
| Subject: | #29758 [Opn->Bgs]: 'and' produces erroneous results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-64944@lists.php.net to get a copy of this message | ||
ID: 29758
Updated by: derick@php.net
Reported By: bd at avatartechnology dot com
-Status: Open
+Status: Bogus
Bug Type: Performance problem
Operating System: Linux RedHat 7.3
PHP Version: 4.3.8
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
No, && and and have a different priority (compare to = and ==).
http://no.php.net/manual/en/language.operators.php#language.operators.precedence
Previous Comments:
------------------------------------------------------------------------
[2004-08-19 15:54:45] bd at avatartechnology dot com
Description:
------------
Ran into a situation where code that utilized the operator 'and'
produced erroneous results.
$free_shipping = true;
$add_fee = 'Y';
$free_shipping = $free_shipping and $add_fee == 'N';
This was producing the result where $free_shipping was always true.
Adding parenthesis makes no difference in result.
--------------
$free_shipping = true;
$residential_fee = 'Y';
$free_shipping = $free_shipping && $residential_fee == 'N';
This accurately produces the correct results.
--------------
According to the documentation on PHP website 'and' and '&&' should be
used interchangably with same results.
Reproduce code:
---------------
$free_shipping = true;
$residential_fee = 'Y';
$free_shipping = $free_shipping and $residential_fee == 'N';
printf("free = %d",$free_shipping);
Expected result:
----------------
free = 0
Actual result:
--------------
free = 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29758&edit=1