Re: [RFC] Interval Comparison

From: Date: Sat, 12 Nov 2016 10:08:08 +0000
Subject: Re: [RFC] Interval Comparison
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-96840@lists.php.net to get a copy of this message
On 2016-11-11 19:03, David Walker wrote:
I took a quick stab at implementing, and had something working for constant expressions, but handling something akin to: $a = 2; if (1 < $a++ < 3) { ... } Is a bit awkward in our expansions of : if (1 < $a++ && $a++ < 3). Seems as if when processing the chain here, you'd need to see if the left node has a child, and somehow ensure you get the evaluated value somehow, to override the "left" node. So logically expansion of the above would be if (1 < $a++ && 3 < 3). I think the same would have too somehow handle (either by syntax error or something) that if a non-numeric value creeps into a binary-op-compare we error like: if (1 < (2==3) < 3). Just some food for thought -- Dave
I don't see how you would ”logically” get 3 < 3. The very point of chaining is that each expression is evaluated only once, so the expression will have the same value in both of the comparisons. So if the first part is 1<2, then the other must be 2<3 (and not 3<3). An expression like a < b < c < d can be currently implemented with temporary variables like this: a < ($tmp1 = b) && $tmp1 < ($tmp2 = c) && $tmp2 < d -- Lauri Kenttä

« previous php.internals (#96840) next »