Bug #12566 Updated: Cascaded ternaries evaluate incorrectly

From: Date: Sat, 04 Aug 2001 21:04:43 +0000
Subject: Bug #12566 Updated: Cascaded ternaries evaluate incorrectly
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-62088@lists.php.net to get a copy of this message
ID: 12566 Updated by: jeroen Reported By: nick@macaw.demon.co.uk Status: Open Bug Type: *Programming Data Structures Operating System: Linux PHP Version: 4.0.6 New Comment: Confirmed in latest CVS: --- echo TRUE ? 'one' : TRUE ? 'two' : 'unknown'; => two --- echo TRUE ? 'one' : FALSE ? 'two' : 'unknown'; => two --- This definitely is a bug, and IMO a serious one. A parse error would be acceptable IMO (then use ( and )), but this isn't. Previous Comments: ------------------------------------------------------------------------ [2001-08-04 15:33:28] nick@macaw.demon.co.uk 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 this bug report at http://bugs.php.net/?id=12566&edit=1

« previous php.dev (#62088) next »