Is the PHP ternary operator broken?
This C code does what I expect:
Code:
#include <stdio.h>
int main(){
int x = 3;
int y = (x<3)?1:(x<4)?2:(x<6)?3:4;
printf("%d\n", y);
return 0;
}
It prints the number 2.
This PHP code does not:
Code:
<?php
$x = 3;
$y = ($x<3)?1:($x<4)?2:($x<6)?3:4;
echo $y."\n";
?>
Instead I get 3
It only seems to evaluate the last expression. Anyone know if this would be a bug, or if there is a reason for this?
I dont like it :(
Edit: found the answer, http://bugs.php.net/bug.php?id=25356. Guess I should have searched first...