|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-24 19:48 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 00:00:01 2025 UTC |
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.