Hi, Fleshgrinder wrote:
It is not very readable and repetitive. It would be interesting to support a more mathematical notation for this:``` if (0 < $x < 42) { echo 'x is in (0, 42)'; } if (0 <= $x <= 42) { echo 'x is in [0, 42]'; } ``` I cannot judge how complicated it is to extend the Bison definitions to allow this. However, if there is interest I'm sure there is a way. :)
Python supports this, I believe it lets you use arbitrary chains of comparisons.
PHP is in the fortunate position where the associativity of the comparison operators is undefined. That is, `0 < $x < 42` is currently invalid syntax. Some other languages made the (in my view) mistake of defining a precedence here, so that it gets interpreted as `(0 < $x) < 42`, which is (generally?) useless. PHP doesn't have this problem.
I've wanted to do this myself, but figuring out how to implement it was tricky, so I didn't spend much time on it. But it's certainly possible, and I'd appreciate this if it was added.
Thanks for bringing it up! -- Andrea Faulds https://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
