Skip to content

Commit 80b94df

Browse files
committed
Fixed bug #62976 (Notice: could not be converted to int when comparing some builtin classes)
If both of the objects can't be casted to compare, they are not equal
1 parent 8afb848 commit 80b94df

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Zend/zend_operators.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
14731473
return ret;
14741474
}
14751475
}
1476+
14761477
if (Z_TYPE_P(op2) == IS_OBJECT) {
14771478
if (Z_OBJ_HT_P(op2)->get) {
14781479
op_free = Z_OBJ_HT_P(op2)->get(op2 TSRMLS_CC);
@@ -1491,6 +1492,12 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
14911492
return ret;
14921493
}
14931494
}
1495+
1496+
if (Z_TYPE_P(op1) == IS_OBJECT && Z_TYPE_P(op2) == IS_OBJECT) {
1497+
ZVAL_LONG(result, -1);
1498+
return SUCCESS;
1499+
}
1500+
14941501
if (!converted) {
14951502
if (Z_TYPE_P(op1) == IS_NULL) {
14961503
zendi_convert_to_boolean(op2, op2_copy, result);

ext/spl/tests/bug62976.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #62976 (Notice: could not be converted to int when comparing some builtin classes)
3+
--FILE--
4+
<?php
5+
6+
var_dump(new stdClass() == new ArrayObject());
7+
var_dump(new stdClass() == new Exception());
8+
var_dump(new ArrayObject() == new ArrayObject());
9+
var_dump(new ArrayObject(array(1, 2)) == new ArrayObject());
10+
?>
11+
--EXPECTF--
12+
bool(false)
13+
bool(false)
14+
bool(true)
15+
bool(false)

tests/lang/compare_objects_basic2.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ var_dump($obj1 == $obj2);
2020
===DONE===
2121
--EXPECTF--
2222
Simple test comparing two objects with different compare callback handler
23-
24-
Notice: Object of class X could not be converted to int in %s on line %d
25-
26-
Notice: Object of class DateTime could not be converted to int in %s on line %d
27-
bool(true)
23+
bool(false)
2824
===DONE===

0 commit comments

Comments
 (0)