Skip to content

Fix SplHeap::compare arginfo and tests #3686

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

Closed
wants to merge 1 commit into from

Conversation

morrisonlevi
Copy link
Contributor

No description provided.

@petk petk added the Quickfix label Nov 27, 2018
}
class SplHeap2 extends SplHeap {
public function compare($a, $b) {
return -parent::compare($a, $b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Stupid question): what does - do here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The - prefix negates the return value, so if the right operand returns 8, then this will return -8

@@ -1192,7 +1192,7 @@ static const zend_function_entry spl_funcs_SplHeap[] = {
SPL_ME(SplHeap, valid, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, recoverFromCorruption, arginfo_splheap_void, ZEND_ACC_PUBLIC)
SPL_ME(SplHeap, isCorrupted, arginfo_splheap_void, ZEND_ACC_PUBLIC)
ZEND_FENTRY(compare, NULL, NULL, ZEND_ACC_PROTECTED|ZEND_ACC_ABSTRACT)
ZEND_FENTRY(compare, NULL, arginfo_heap_compare, ZEND_ACC_PROTECTED|ZEND_ACC_ABSTRACT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC, isn't? 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding arginfo is BC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BC breaks go to PHP 8 or is it something that PHP 7.4 can handle as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petk BC goes only in PHP 8. See #3443 for example, as well #74035 and #75958

@nikic
Copy link
Member

nikic commented Nov 28, 2018

The main thing I'd be concerned about is that a user implements compare with compare(Foo $a, Foo $b), which would no longer satisfy this signature (even with parameter contravariance -- this would need generics to work).

@carusogabriel
Copy link
Contributor

This can be merged against master now :)

@krakjoe
Copy link
Member

krakjoe commented Jan 31, 2019

I'm not certain that Nikita's concern has been or is going to be addressed ?

What do you think about this now @nikic ?

@nikic
Copy link
Member

nikic commented Jan 31, 2019

I'm conflicted here. On the one hand, this change is going to make ergonomics worse, because people will no longer be able to typehint their compare() methods. On the other hand, the way this is currently achieved is through a dirty engine hack that probably shouldn't exist in the first place.

Overall I think we should merge this for PHP 8. Not a lot of people override this method and the current behavior is inconsistent with how PHP usually works.

We may also make availability of arginfo a hard requirement in future, in which case this would no longer work anyway.

@nikic nikic added this to the PHP 8.0 milestone Feb 8, 2019
@nikic
Copy link
Member

nikic commented Feb 8, 2019

Merged as 780bdcd into master.

@nikic nikic closed this Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants