Bug #10351 Updated: Parsing problem with nested ? : structures
ID: 10351 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Closed +Status: Open Bug Type: Feature/Change Request Operating System: Sun OS 5.7 PHP Version: 4.0.3pl1 New Comment: See comment starting with "I checked...". Previous Comments: [2002-04-29 10:34:57] [EMAIL PROTECTED] I checked, and < has a higher precedence than ?: as one would expect. For example, with $dHour = 5, this is equivalent to: $departmeals = 1 ? 1 ? "3" : "2" : 1 ? "1" : "0"; which should evaluate to "3" but evaluates to "1" instead. The C language has no trouble with this construction: sun-66% cat temp.c #include main(){ printf("%s\n",1 ? 1 ? "3" : "2" : 1 ? "1" : "0"); } sun-66% cc temp.c sun-66% a.out 3 [2002-04-27 15:19:22] [EMAIL PROTECTED] it does execute correctly, given the relative precedence of the '<' and '?:' operators. [2001-04-16 16:14:48] [EMAIL PROTECTED] The following statement does not execute correctly: $departmeals = $dHour < 10.5 ? $dHour < 6.0 ? "3" : "2" : $dHour < 18.0 ? "1" : "0"; No error message--it just returns the wrong result. It does execute correctly if parentheses are added: $departmeals = $dHour < 10.5 ? ($dHour < 6.0 ? "3" : "2") : ($dHour < 18.0 ? "1" : "0"); The original is not ambiguous; it should parse and execute correctly. -- Edit this bug report at http://bugs.php.net/?id=10351&edit=1
Bug #10351 Updated: Parsing problem with nested ? : structures
ID: 10351 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Closed Bug Type: Feature/Change Request Operating System: Sun OS 5.7 PHP Version: 4.0.3pl1 New Comment: I checked, and < has a higher precedence than ?: as one would expect. For example, with $dHour = 5, this is equivalent to: $departmeals = 1 ? 1 ? "3" : "2" : 1 ? "1" : "0"; which should evaluate to "3" but evaluates to "1" instead. The C language has no trouble with this construction: sun-66% cat temp.c #include main(){ printf("%s\n",1 ? 1 ? "3" : "2" : 1 ? "1" : "0"); } sun-66% cc temp.c sun-66% a.out 3 Previous Comments: [2002-04-27 15:19:22] [EMAIL PROTECTED] it does execute correctly, given the relative precedence of the '<' and '?:' operators. [2001-04-16 16:14:48] [EMAIL PROTECTED] The following statement does not execute correctly: $departmeals = $dHour < 10.5 ? $dHour < 6.0 ? "3" : "2" : $dHour < 18.0 ? "1" : "0"; No error message--it just returns the wrong result. It does execute correctly if parentheses are added: $departmeals = $dHour < 10.5 ? ($dHour < 6.0 ? "3" : "2") : ($dHour < 18.0 ? "1" : "0"); The original is not ambiguous; it should parse and execute correctly. -- Edit this bug report at http://bugs.php.net/?id=10351&edit=1