This is a sort of "working-as-intended-even-though-it's-clearly-wrong" behaviour of PHP. It doesn't associate that way, so while this code works in most other languages, it will fail in PHP. Lesson? Learn to use parenthesis over unusual association paradigms. Lesson Two? Ternary isn't a magic bullet, while it can be nice and compact, it should only be used when it's readable. IMHO nested ternary statements are just ugly.