if statement - Dangers/side-effects of using PHP's ternary operator as a control structure -


a coworker uses php's ternary operator control structure, rather rhs of expression. 1 such example:

list==''?list=val:list=list+','+val; 

(in example, statement called in loop add values string, ensuring comma separator doesn't appear if there's 1 item.) in essence, relies on expression evaluation work, , throws away expression result.

aside fact it's hard on eyes, there reason avoid construct? it's syntactically legal; , executes correctly. i'm ternary operator wasn't designed used in manner, , wonder if there consequences doing so.

it work fine, , don't see problem apart readability.

if think it's hard on eyes, replace loop , line call implode function.


Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -