ID:          41228
 Updated by:  [EMAIL PROTECTED]
 Reported By: terminatorul at gmail dot com
 Status:      Open
 Bug Type:    Documentation problem
 PHP Version: Irrelevant
 New Comment:

Agreed.

<?php
// Echo's F and does NOT set $a.
echo (False && ($a=1)) ? 'T' : 'F';

// Echo's T, sets $b but does not set $c.
echo (($b=2) || False || ($c=3)) ? 'T':'F';

// Turn off notices about undefined variables for $a and $c.
error_reporting(E_ALL & ~E_NOTICE);

// Rather than "1 2 3", we get just " 2 ".
echo "$a $b $c";
?>


Previous Comments:
------------------------------------------------------------------------

[2007-04-29 18:29:26] terminatorul at gmail dot com

Description:
------------
The manual page for logical operators

http://www.php.net/manual/en/language.operators.logical.php

should warn users that the right-hand operand of && or ||
will never be evaluated if that is not necesary

For example when doing:

$result = FALSE && mysql_query($query);

than the mysql $query will never get executed.

Or at least the page should advise users to never rely on side-effects.

Reproduce code:
---------------
http://www.php.net/manual/en/language.operators.logical.php

Expected result:
----------------
The page should say something like:

For the binary logical operators the second operand will never be
evaluated when it is clear from the first operand what the result will
be.

For example the code

$prev_status = FALSE;
$crt_status = $prev_status && mysql_query($query);
echo mysql_affected_rows();

will never execute the query, simply because $crt_status will be FALSE
no matter what mysql_query() would return.

Actual result:
--------------
Right now I can see nothing about side-effects in the page.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41228&edit=1

Reply via email to