-
Couldn't load subscription status.
- Fork 8k
Implement <=> (spaceship/comparison) operator #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
| Huh, I had no idea there was prior art RFC-wise. Maybe @dshafik would let me take over that RFC. I like his token name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add some objects - like GMP - here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. This is based on the > test, so the others should be updated if that's the case.
c2b0fe1 to d8f2d82 Compare | @TazeTSchnitzel okey. you are right... I am in a insane status now. |
| what point would this even serve? lol |
| @r3wt It makes it easier to write comparison functions used in sorting, for example. |
| @TazeTSchnitzel great , it is really useful, especially when building neural networks |
aa3a349 to a0f4652 Compare a0f4652 to d8b7a44 Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Andrea! Why not use (!$failed) or $failed === false? Strict comparisons are nicer if possible. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's like that because this is based on either the >= or the <= test (can't remember). It wasn't a deliberate choice on my part.
I could fix it, but I don't see the point, especially as it'd just make this inconsistent with the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess those tests date back to a time when strict comparisons where not that popular! And thanks for the hard work :)
| Hi, Sorry, I don't know if it's the best place to comment the RFC https://wiki.php.net/rfc/combined-comparison-operator I'm surprised by PHP adds <=> operator in PHP 7, while Python 3 dropped cmp(). cmp() was dropped because it had many issues. Example: |
| @Haypo from what I can see, Python's removal of |
PHP has also objects which have surprising behaviour on comparison. For example, float not a number (NaN). Try with "$nan = acos(8);". What should be the result of $a <=> $b for NaN? See also:
|
| Those aren't objects. |
| @smalyshev I just rebased the branch onto master and squashed the commits, FYI. (This pull request is dead, though.) |
| @TazeTSchnitzel why is it closed and dead is you said , it is a great feature ? |
| @Ragazzo I quit PHP development. However, @smalyshev revived it, and it passed. |
| Changes Unknown when pulling d8b7a44 on TazeTSchnitzel:spaceship_operator into * on php:master*. |
| why is @coveralls bothering me about this. the pull request is closed. |
| @TazeTSchnitzel asking the right questions. I got the email too. |
Implementation of RFC: https://wiki.php.net/rfc/combined-comparison-operator
Also see Implement cmp() function.