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

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -