Bug #12566: Cascaded ternaries evaluate incorrectly
| From: | nick at macaw dot demon dot co dot uk | Date: | Sat, 04 Aug 2001 19:33:28 +0000 |
| Subject: | Bug #12566: Cascaded ternaries evaluate incorrectly | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-62081@lists.php.net to get a copy of this message | ||
From: nick@macaw.demon.co.uk
Operating system: Linux
PHP version: 4.0.6
PHP Bug Type: *Programming Data Structures
Bug description: Cascaded ternaries evaluate incorrectly
The following emits 'two' rather than 'one' as one would expect.
$a = 1; $b = 2;
echo (($a == 1) ? 'one' :
($b == 2) ? 'two' :
'unknown');
Apologies if for PHP this unusual behaviour actually is as expected, but
being counter-intuituve, and of course inconsistent from other languages
with a ?: operator, this is an undesirable result.
In 'C', the following of course outputs 'one'
#include <stdio.h>
int main()
{
int a = 1, b = 2;
puts((a == 1) ? "one" :
(b == 2) ? "two" :
"unknown");
return 0;
}
--
Edit bug report at: http://bugs.php.net/?id=12566&edit=1