AW: [PHP] reason for a "Notice:.." on one site but not another? (Same code.)
| From: | Ralph Deffke | Date: | Mon, 10 Aug 2009 19:17:20 +0000 |
| Subject: | AW: [PHP] reason for a "Notice:.." on one site but not another? (Same code.) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296563@lists.php.net to get a copy of this message | ||
the single & is a logical AND so a() NOR b() is evaluatet ! its usually used on binary integer.
e.g. 0x0001 & 0x0001 = 0x0001 equlals TRUE while 0x0002 & 0x0001 equals FALSE
so something like $a & $b guides to some very interisting results depending of their values
but nothing u expect.
while && tells 'evaluate' the expressions on both sites and combine its results in
an AND operation.
thats why compilers and interpreters do have a definition what value TRUE has.
its very likely that TRUE is 1 and false is 0
lets say
$a = 1
$b = 1
then
$a & $b is 1 or true and it would give the same like
$a && $b in that case
at that point its also to mention that an empty string in PHP is NOT == FALSE
this gives the following result on an empty string:
$a = "";
isset( $a ) == TRUE
while
$a = null;
isset( $a ) == FALSE;
for the same story there are the
==
===
and
!=
!===
operators
________________________________
Von: Martin Scotta <martinscotta@gmail.com>
An: Andrew Ballard <aballard@gmail.com>
CC: Ralph Deffke <ralph_deffke@yahoo.de>; php-general@lists...php.net
Gesendet: Montag, den 10. August 2009, 20:40:19 Uhr
Betreff: Re: [PHP] reason for a "Notice:.." on one site but not another? (Same code.)
This "intelligence" is given by the laziness of the && operator.
$res = a() && b(); # if a() is false then b() does not evaluate
$res = a() & b(); # b() evaluates no matter a()'s result
so, order matters.
On Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard <aballard@gmail...com> wrote:
On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke<ralph_deffke@yahoo.de> wrote:
>>> this is not "intelligence" its just pure math. the '&&'
>>> says if BOTH
>>> expressions are true then the whole expression is true.
>>>
>>> so if the first one is false, the whole is false, why checking the next one
>>> in the underlaying C it would be something like this
>>> {
>>> if ( expression == false ) return false;
>>> if ( expression == false) return false;
>>> return true;
>>> }
>>>
>>> ralph
>>> ralph_deffke@yahoo.de
>
>That's logically correct, and while PHP does implement this
>>"short-circuit" logic, not all languages do. In that regard, I
>>appreciate what John meant by saying it makes it look "more
>>intelligent." Some languages evaluate each of the conditions to their
>>respective boolean results before evaluating the logical operators.
>
>>Andrew
>
>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Martin Scotta