r/shittyprogramming • u/calsosta • Nov 30 '18
Friday Code Confessions
If you have been living with technical debt and want absolution here is your opportunity.
Confess your sins and receive your penance.
155
Upvotes
View all comments
Show parent comment
7
u/asm_ftw Dec 01 '18 edited Dec 01 '18
They are the opposite associativity than every other language that does ternary conditionals, preventing you from doing
X = ( expr_1 ) ? Value_a :
( expr_2 ) ? Value_b :
( expr_3) ? Value_c :
Value_d ;
Where X gets assigned in an if-elseif-elseif-else paradigm. It can declutter blocks of code where you have a lot of ugly if-elseif-else blocks for just setting values to a variable, at the cost of being a little confusing for the uninitiated, but PHP, and only PHP, does not let you do that, while still providing the operator.