On 05.03.2020 at 13:05, Nikita Popov wrote:

>> Given that we have internal classes which deliberately have such
>> comparison behavior (i.e. returning 0 or 1, to signal that there is no
>> order defined), e.g. Closures[1], I tend to prefer raising a warning
>> instead of trying to recover.
>>
>> [1]
>> <https://github.com/php/php-src/blob/php-7.4.3/Zend/zend_closures.c#L372>
>
> This is a different case. The problem with my example is that it reports
> equality where none exists, which is an issue if you try to change the
> ordering of equal elements. Your case (which is indeed somewhat common in
> extension code) always returns "greater-than" for non-equal elements. The
> end result here is that the sort will not have any defined order regardless
> of how we perform it. We can't really do anything about such cases.

Oops, of course.  Thanks for clarifying! :)

> I expect that a proposal for userland compare and equality overloading may
> want to make the "not ordered" case more explicit, in which case we could
> throw a warning when such comparisons are performed as part of sorting.

ACK.

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to