summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-03-31 12:36:48 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-03-31 12:36:48 +0200
commitfb5bfcb75b5a6abec2a07567769f6ae635d4399e (patch)
tree16db1a73ec8b5733aff504b55c58e3211989a5d9
parentbef4b2e4e97ea6d1443660326c19bab957314aac (diff)
downloadphp-git-fb5bfcb75b5a6abec2a07567769f6ae635d4399e.tar.gz
Add a ZEND_UNCOMPARABLE value
To explicitly indicate that objects are uncomparable. For now this has no functional difference from the usual 1 return value, but makes intent clearer.
-rw-r--r--Zend/zend_object_handlers.c4
-rw-r--r--Zend/zend_operators.h6
-rw-r--r--ext/date/php_date.c6
-rw-r--r--ext/intl/breakiterator/breakiterator_class.cpp3
-rw-r--r--ext/intl/timezone/timezone_class.cpp2
-rw-r--r--ext/pdo/pdo_dbh.c2
-rw-r--r--ext/pdo/pdo_stmt.c4
-rw-r--r--ext/simplexml/simplexml.c2
-rw-r--r--ext/spl/spl_observer.c2
9 files changed, 17 insertions, 14 deletions
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 82e189f92c..fb3b7509df 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -1617,7 +1617,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
return ret;
}
}
- return 1;
+ return ZEND_UNCOMPARABLE;
}
zobj1 = Z_OBJ_P(o1);
@@ -1627,7 +1627,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
return 0; /* the same object */
}
if (zobj1->ce != zobj2->ce) {
- return 1; /* different classes */
+ return ZEND_UNCOMPARABLE; /* different classes */
}
if (!zobj1->properties && !zobj2->properties) {
zend_property_info *info;
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index 8b9e06f17e..cf6d6dd824 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -401,6 +401,12 @@ again:
return result;
}
+/* Indicate that two values cannot be compared. This value should be returned for both orderings
+ * of the operands. This implies that all of ==, <, <= and >, >= will return false, because we
+ * canonicalize >/>= to </<= with swapped operands. */
+// TODO: Use a different value to allow an actual distinction here.
+#define ZEND_UNCOMPARABLE 1
+
ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2);
ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2);
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 00d7892a6a..ed24895965 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1903,7 +1903,7 @@ static int date_object_compare_date(zval *d1, zval *d2) /* {{{ */
if (!o1->time || !o2->time) {
php_error_docref(NULL, E_WARNING, "Trying to compare an incomplete DateTime or DateTimeImmutable object");
- return 1;
+ return ZEND_UNCOMPARABLE;
}
if (!o1->time->sse_uptodate) {
timelib_update_ts(o1->time, o1->time->tz_info);
@@ -2040,7 +2040,7 @@ static int date_object_compare_timezone(zval *tz1, zval *tz2) /* {{{ */
if (o1->type != o2->type) {
php_error_docref(NULL, E_WARNING, "Trying to compare different kinds of DateTimeZone objects");
- return 1;
+ return ZEND_UNCOMPARABLE;
}
switch (o1->type) {
@@ -3901,7 +3901,7 @@ static int date_interval_compare_objects(zval *o1, zval *o2) {
* smaller, equal or greater depending on the point in time at which the interval starts. As
* such, we treat DateInterval objects are non-comparable and emit a warning. */
zend_error(E_WARNING, "Cannot compare DateInterval objects");
- return 1;
+ return ZEND_UNCOMPARABLE;
}
/* {{{ date_interval_read_property */
diff --git a/ext/intl/breakiterator/breakiterator_class.cpp b/ext/intl/breakiterator/breakiterator_class.cpp
index 301701d29e..bd76d25ca6 100644
--- a/ext/intl/breakiterator/breakiterator_class.cpp
+++ b/ext/intl/breakiterator/breakiterator_class.cpp
@@ -84,9 +84,6 @@ static int BreakIterator_compare_objects(zval *object1,
*bio2;
ZEND_COMPARE_OBJECTS_FALLBACK(object1, object2);
- if (Z_TYPE_P(object1) != Z_TYPE_P(object2)) {
- return 1; /* object and non-object */
- }
bio1 = Z_INTL_BREAKITERATOR_P(object1);
bio2 = Z_INTL_BREAKITERATOR_P(object2);
diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp
index 8a8ac2e29c..11a9177320 100644
--- a/ext/intl/timezone/timezone_class.cpp
+++ b/ext/intl/timezone/timezone_class.cpp
@@ -285,7 +285,7 @@ static int TimeZone_compare_objects(zval *object1, zval *object2)
}
}
- return 1;
+ return ZEND_UNCOMPARABLE;
}
/* }}} */
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index c6b18b249b..65e324a2b7 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1298,7 +1298,7 @@ out:
static int dbh_compare(zval *object1, zval *object2)
{
- return -1;
+ return ZEND_UNCOMPARABLE;
}
static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 162b47ee6c..37e7a4c403 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2165,7 +2165,7 @@ out:
static int dbstmt_compare(zval *object1, zval *object2)
{
- return -1;
+ return ZEND_UNCOMPARABLE;
}
zend_object_handlers pdo_dbstmt_object_handlers;
@@ -2585,7 +2585,7 @@ static zend_string *row_get_classname(const zend_object *object)
static int row_compare(zval *object1, zval *object2)
{
- return -1;
+ return ZEND_UNCOMPARABLE;
}
void pdo_row_free_storage(zend_object *std)
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index e7cd877906..99ca0b2aa1 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1297,10 +1297,10 @@ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
} else if (sxe1->document->ptr == sxe2->document->ptr) {
return 0;
}
+ return 1;
} else {
return !(sxe1->node == sxe2->node);
}
- return 1;
}
/* }}} */
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 03765fe7f7..ad00a12e4b 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -345,7 +345,7 @@ static int spl_object_storage_compare_objects(zval *o1, zval *o2) /* {{{ */
zo2 = (zend_object *)Z_OBJ_P(o2);
if (zo1->ce != spl_ce_SplObjectStorage || zo2->ce != spl_ce_SplObjectStorage) {
- return 1;
+ return ZEND_UNCOMPARABLE;
}
return zend_hash_compare(&(Z_SPLOBJSTORAGE_P(o1))->storage, &(Z_SPLOBJSTORAGE_P(o2))->storage, (compare_func_t)spl_object_storage_compare_info, 0);