You misunderstood operator associativity. It's simply the way to group operators with the same precedence and doesn't affect order of evaluation in any way. So cond1 ? 1 : cond2 ? 2 : cond3 ? 3 : 4
will be parsed as
cond1 ? 1 : (cond2 ? 2 : (cond3 ? 3 : 4))
from the right and not as
((cond1 ? 1 : cond2) ? 2 : cond3) ? 3 : 4
which groups operands from the left. Once parentheses are added then the expression will be evaluated in its normal order
In fact PHP made the ternary operator left-associative which is one of its biggest mistake and it's unfixable by now
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…