Re: Possible problem in the parser

From: Date: Wed, 12 Mar 2003 18:35:31 +0000
Subject: Re: Possible problem in the parser
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-95089@lists.php.net to get a copy of this message
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

« previous php.dev (#95089) next »