RE: [PHP-DEV] Possible problem in the parser

From: Date: Thu, 13 Mar 2003 13:58:04 +0000
Subject: RE: [PHP-DEV] Possible problem in the parser
Groups: php.dev 
Request: Send a blank email to php-dev+get-95157@lists.php.net to get a copy of this message
> -----Original Message----- > From: Andrey Hristov [mailto:andrey@webgate.bg] > Sent: 12 March 2003 17:26 > > > On Wed, 12 Mar 2003, Andrey Hristov wrote: > > > > > Few minutes ago I found the following behaviour somehow > wierd for me : > > > > Known bug, the associativity of the ternary operator has been > > broken since ages in the engine. It's on the "won't be > > fixed" sheet, because of BC concerns. That's a bit hard -- it's different from c, certainly (left associative instead of right), but that's a valid choice (even if it was originally accidental!) and calling it broken is a bit harsh. > > Is it documented somewhere? Yes -- at http://www.php.net/manual/en/language.operators.php#language.operators.prece dence). 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; yielding 5 if a==1 or a==2, else 6. But in right-associative c, it's equivalent to: b = a==1? 4:(a==2? 5:6); yielding 4 if a==1, 5 if a==2, else 6. Since this *is* documented behaviour, I don't see how it can be called particularly unexpected. ("Weird", maybe, if you're used to the c behaviour, but not unexpected!) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.dev (#95157) next »