Skip to content

Fixed bug #62976 (Notice: could not be converted to int when comparing s... #179

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
return ret;
}
}

if (Z_TYPE_P(op2) == IS_OBJECT) {
if (Z_OBJ_HT_P(op2)->get) {
op_free = Z_OBJ_HT_P(op2)->get(op2 TSRMLS_CC);
Expand All @@ -1491,6 +1492,12 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
return ret;
}
}

if (Z_TYPE_P(op1) == IS_OBJECT && Z_TYPE_P(op2) == IS_OBJECT) {
ZVAL_LONG(result, -1);
return SUCCESS;
}

if (!converted) {
if (Z_TYPE_P(op1) == IS_NULL) {
zendi_convert_to_boolean(op2, op2_copy, result);
Expand Down
15 changes: 15 additions & 0 deletions ext/spl/tests/bug62976.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #62976 (Notice: could not be converted to int when comparing some builtin classes)
--FILE--
<?php

var_dump(new stdClass() == new ArrayObject());
var_dump(new stdClass() == new Exception());
var_dump(new ArrayObject() == new ArrayObject());
var_dump(new ArrayObject(array(1, 2)) == new ArrayObject());
?>
--EXPECTF--
bool(false)
bool(false)
bool(true)
bool(false)
6 changes: 1 addition & 5 deletions tests/lang/compare_objects_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@ var_dump($obj1 == $obj2);
===DONE===
--EXPECTF--
Simple test comparing two objects with different compare callback handler

Notice: Object of class X could not be converted to int in %s on line %d

Notice: Object of class DateTime could not be converted to int in %s on line %d
bool(true)
bool(false)
===DONE===