just to add that "," (comma) is not working in ternary operator :/ ( posted an example for that but forgot to specify the problem)
Andrey ----- Original Message ----- From: "Marcus Börger" <[EMAIL PROTECTED]> To: "Derick Rethans" <[EMAIL PROTECTED]> Cc: "Andrey Hristov" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, March 12, 2003 8:35 PM Subject: Re: [PHP-DEV] Possible problem in the parser > At 18:42 12.03.2003, Derick Rethans wrote: > >On Wed, 12 Mar 2003, Andrey Hristov wrote: > > > > > Few minutes ago I found the following behaviour somehow wierd for me : > > > <?php > > > $a = 1; > > > $b = $a==1? 4:$a==2? 5:6; > > > printf("a[%d]b[%d]\n", $a, $b); > > > ?> > > > Prints : > > > a[1]b[5] > > > > > > Similar C program : > > > main() > > > { > > > int a,b; > > > a = 1; > > > b = a==1? 4:a==2? 5:6; > > > printf("a[%d]b[%d]\n", a, b); > > > } > > > Prints : > > > a[1]b[4] > > > > > > -=-=-=-=-=- > > > I think that the behavior of the C program is the right > > > >It's just a different operator precedence; it's not really wrong, just > >different. > > > Where is the different precednece here? I can only find an error. > Lets support parantesis: > > ALL BUT PHP) '==' has higher precedence than '?:' > > ((a==1) ? 4 : ((a==2) ? 5 : 6)) => (1) ? 4 : ((0) ? 5 : 6) => 1 ? 4 : 6 => 4 > > PHP?) '?:' has higher precedence than '==' > > (a == (1 ? 4 : a) == (2 ? 5 : 6)) > > ( a == (4) == (5)) > > Now what? Assume order left from to right: ( (a == (4)) == (5) => (0 == 5) => 0 > > Or right to left (which contradicts rest of PHP behavior): ( a == ((4) == > (5))) => (a == 0) => 0 > > Result: This is (to say it in german "mumpitz") wrong. > > So lets fix it. > > marcus > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php