Andrea Faulds wrote on 05/12/2014 14:47:
On 5 Dec 2014, at 14:36, Дмитрий <fr...@pop3.ru> wrote:
Hi!
I followed by https://wiki.php.net/rfc/howto and I would like to propose a concept
"comparison chain" to implementing to future PHP versions.
It would be very usable if PHP can do that in python-style.
Thank for your attension!
Are you saying to allow (1 < x < 2) etc.? That would be nice, although it’s a
backwards-compatibility break as currently (1 < x < 2) would do something different,
as would, say, ($x == $y == $z).
For those of us that don't know Python, an explanation might be handy.
From a quick search, this StackOverflow answer sums it up quite nicely,
assuming it's correct: http://stackoverflow.com/a/25753528/157957
So, "$a < $b < $c" would be short-hand for "$a < $b && $b < $c". It
would short-circuit in exactly the same way, and be extended to any
number of comparison operators.
The obvious use case is for maths style "is between" notation, e.g. if (
10 < $total <= 100 )
Is this correct, a) for Python, and b) for what is suggested for PHP?
As Andrea notes, it would be a backwards compatibility, although the
chances of anyone deliberately using a boolean as operand to a < or >
are unlikely, and that's what's currently implied by $x < $y < $z.
Perhaps if == was left out of the mix, so that $x == $y == true would
evaluate the same way it does now, that might be a working compromise?
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php