Edit report at http://bugs.php.net/bug.php?id=51546&edit=1

 ID:               51546
 User updated by:  michaelozeryansky at hotmail dot com
 Reported by:      michaelozeryansky at hotmail dot com
 Summary:          If shorthand statement
 Status:           Bogus
 Type:             Bug
 Package:          *General Issues
 Operating System: Linux
 PHP Version:      5.2.13

 New Comment:

Thank you, I was forgot to mention if i used parenthesis then it works
fine, but I still thought there was an issue.



Now I know, and thank you.


Previous Comments:
------------------------------------------------------------------------
[2010-04-13 05:52:54] ahar...@php.net

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.

------------------------------------------------------------------------
[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

Reply via email to