-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added fallthrough for == operator with objects for extensions #7973
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
base: master
Are you sure you want to change the base?
Changes from all commits
348feb7
2fa6155
2be2077
de984eb
c6440fa
8a2b6cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -501,7 +501,11 @@ ZEND_VM_HELPER(zend_is_equal_helper, ANY, ANY, zval *op_1, zval *op_2) | |
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) { | ||
op_2 = ZVAL_UNDEFINED_OP2(); | ||
} | ||
ret = zend_compare(op_1, op_2); | ||
if (Z_TYPE_P(op_1) == IS_OBJECT || Z_TYPE_P(op_2) == IS_OBJECT) { | ||
ret = zend_equals_object(op_1, op_2, ZEND_IS_EQUAL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you need a separate zend_equals that is pushed through the entire hierarchy. Otherwise objects nested in arrays will not use the correct handler, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, exactly. |
||
} else { | ||
ret = zend_compare(op_1, op_2); | ||
} | ||
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) { | ||
zval_ptr_dtor_nogc(op_1); | ||
} | ||
|
@@ -581,7 +585,11 @@ ZEND_VM_HELPER(zend_is_not_equal_helper, ANY, ANY, zval *op_1, zval *op_2) | |
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) { | ||
op_2 = ZVAL_UNDEFINED_OP2(); | ||
} | ||
ret = zend_compare(op_1, op_2); | ||
if (Z_TYPE_P(op_1) == IS_OBJECT || Z_TYPE_P(op_2) == IS_OBJECT) { | ||
ret = zend_equals_object(op_1, op_2, ZEND_IS_NOT_EQUAL); | ||
} else { | ||
ret = zend_compare(op_1, op_2); | ||
} | ||
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) { | ||
zval_ptr_dtor_nogc(op_1); | ||
} | ||
|
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.
Can the fallback to the compare handler be in here?
Do we really need to pass the opcode here? I think it would be better for the return value to indicate whether it equals or not (possibly with an equals/not_equals/uncomparable enum). This would prevent inconsistent
==
and!=
implementations by design.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.
The reason I didn't put the fallback here is that extensions that used this handler would have to manually implement the fallback again (assuming they wanted to use the compare handler). But yeah, if this function returned a result enum instead of
zend_result
I think the fallback would have to go in here.That's just very different from how the rest of the handlers are done (from what I've seen), and I wanted this code to be similar to other code in the engine.
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.
Not sure I get what you mean here -- if they want to use some custom logic and then fall back to the default, they can call zend_std_equals_objects to do so.
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.
Or yeah... they could do the obvious thing you just suggested...
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.
Actually though, what about the case where op1 falls back but op2 has custom logic? How would the default handler for op1 handle that?