From:             jvm at jvmyers dot com
Operating system: Mac OSX 10.4.11
PHP version:      5.2.5
PHP Bug Type:     Strings related
Bug description:  short-circuiting on compound boolean in if expression

Description:
------------
Note: I am on a Mac and PHP 5.2.4 is the most recent version available
from entropy.

Problem: Compound booleans expressed as string args in an 'if' statement
don't 'appear' to work as expected:

Context:
  1.  I generate an array of counters.
  2.  I dynamically generate a compound boolean based on selected counters
in the array.  (Note: since the real array is sparse, I must use the
'empty' operator).
  3.  When I submit the compound boolean as the expression of an 'if'
statement, the 'if' appears to resolve ONLY the first element of the
compound boolean.

Conclusion: appears to be a short-circuiting issue

Case 1: 'if' expression passed as string => "1. Conditions met"
Case 2: same as Case 1, but using catenation operator => "2. Conditions
met"
Case 3: same 'if' expression but passed in context => "3. Conditions not
met"

Reproduce code:
---------------
<?php
$aArray = array(1,0);
$sCondition = "!empty($aArray[0]) && !empty($aArray[1])";
if ($sCondition)
{
        echo "Case 1. Conditions met<br />";
}
else
{
        echo "Case 1. Conditions not met<br />";
}
if ("".$sCondition."")
{
        echo "Case 2. Conditions met<br />";
}
else
{
        echo "Case 2. Conditions not met<br />";
}
if (!empty($aArray[0]) && !empty($aArray[1]))
{
        echo "Case 3. Conditions met<br />";
}
else
{
        echo "Case 3. Conditions not met<br />";
}
?>

Expected result:
----------------
See, Case 3, above.

Actual result:
--------------
See, Case 1 and Case 2, above.

-- 
Edit bug report at http://bugs.php.net/?id=44236&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44236&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44236&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44236&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44236&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44236&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44236&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44236&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44236&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44236&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44236&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44236&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44236&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44236&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44236&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44236&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44236&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44236&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44236&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44236&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44236&r=mysqlcfg

Reply via email to