LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: (Marcus Börger) Date: Sat Mar 15 07:18:22 2003 Subject: RE: Possible problem in the parser
At 13:01 14.03.2003, Ford, Mike [LSS] wrote: > > >Just to make this completely clear, in left-associative PHP > > > > > > b = a==1? 4:a==2? 5:6; > > > > > >is equivalent to > > > > > > b = (a==1? 4:a==2)? 5:6; > > > > > > NO it is not equal. Either '==' has higher precedence OR '?:' has. > > See one of my previous mails where i showed where the error is. > >Yes, it is -- believe me, I've researched this extensively. It is NOT >about precedence, but associativity. If you want me to be totally >completist about this: > >Starting from: > > b = a==1? 4:a==2? 5:6; > >precedence rules make this equivalent to: > > b = (a==1)? 4:(a==2)? 5:6; > >but this is still ambiguous -- which ?: phrase do you evaluate >first? Associativity provides the answer: in PHP, where ?: is left >associative (i.e. the left most ?: is evaluated first), the result is >equivalent to: > > b = ((a==1)? 4:(a==2))? 5:6; > >On the other hand, in c, where ?: is right associative, the equivalent is: > > b = (a==1)? 4:((a==2)? 5:6); > >which, apart from the additional (unnecessary) parentheses around the == >comparisons, is exactly what I said before. > >QED Ok Mike, i did not took left association into accound becuase it is stupid. Since the whole thing is messy at the moment and there is no reason to keep BC for messy things which shouldn't be done anyway i suppose we make ir right associative. Andi? marcus
| Navigate in group php.dev at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by Zareef Ahmed
Powered By PHP Consultants |