Edit report at http://bugs.php.net/bug.php?id=51546&edit=1
ID: 51546 Updated by: ahar...@php.net Reported by: michaelozeryansky at hotmail dot com Summary: If shorthand statement -Status: Open +Status: Bogus Type: Bug Package: *General Issues Operating System: Linux PHP Version: 5.2.13 New Comment: As the note at the end of the manual page at http://au2.php.net/ternary hints at, the associativity of the ternary operator is not particularly obvious. We can't change this now due to potential backward compatibility issues. Previous Comments: ------------------------------------------------------------------------ [2010-04-13 04:23:52] michaelozeryansky at hotmail dot com Description: ------------ When I use nested shorthand if statements the result doesn't seem to follow what I expected. I am not sure if this is a bug, but the results are different in other languages. Test script: --------------- <?php var_dump ((true) ?"a":(true) ?"b":"c") ; // b var_dump ((true) ?"a":(false)?"b":"c") ; // b var_dump ((false)?"a":(true) ?"b":"c") ; // b var_dump ((false)?"a":(false)?"b":"c") ; // c ?> I wrote a c++ script to see what the results should be in another language cout << ((true) ?"a":(true) ?"b":"c") << endl; // result = a cout << ((true) ?"a":(false)?"b":"c") << endl; // result = a cout << ((false)?"a":(true) ?"b":"c") << endl; // result = b cout << ((false)?"a":(false)?"b":"c") << endl; // result = c Expected result: ---------------- The PHP script should print out: a a b c Actual result: -------------- In the comments behind each line ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51546&edit=1