summaryrefslogtreecommitdiff
path: root/Zend/zend_object_handlers.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-03-31 12:17:32 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-03-31 14:37:49 +0200
commit8fd7f02ea4cd595a792ef37e558d357d97bceefa (patch)
treea4684263d41cf407f5cffb725fe319bbc05da75c /Zend/zend_object_handlers.c
parent36935e42eac054a422b7edade69923db7727f268 (diff)
downloadphp-git-8fd7f02ea4cd595a792ef37e558d357d97bceefa.tar.gz
Make cast_object handler required
Avoid subtle differences in behavior depending on whether the handler is absent or returns FAILURE. If you previously set cast_object to NULL, create a handler that always returns FAILURE instead.
Diffstat (limited to 'Zend/zend_object_handlers.c')
-rw-r--r--Zend/zend_object_handlers.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index fb3b7509df..f678277fd2 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -1572,50 +1572,46 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
zval casted;
if (Z_TYPE_P(o1) == IS_OBJECT) {
ZEND_ASSERT(Z_TYPE_P(o2) != IS_OBJECT);
- if (Z_OBJ_HT_P(o1)->cast_object) {
- zend_uchar target_type = (Z_TYPE_P(o2) == IS_FALSE || Z_TYPE_P(o2) == IS_TRUE)
- ? _IS_BOOL : Z_TYPE_P(o2);
- if (Z_OBJ_HT_P(o1)->cast_object(Z_OBJ_P(o1), &casted, target_type) == FAILURE) {
- // TODO: Less crazy.
- if (target_type == IS_LONG || target_type == IS_DOUBLE) {
- zend_error(E_NOTICE, "Object of class %s could not be converted to %s",
- ZSTR_VAL(Z_OBJCE_P(o1)->name), zend_get_type_by_const(target_type));
- if (target_type == IS_LONG) {
- ZVAL_LONG(&casted, 1);
- } else {
- ZVAL_DOUBLE(&casted, 1.0);
- }
+ zend_uchar target_type = (Z_TYPE_P(o2) == IS_FALSE || Z_TYPE_P(o2) == IS_TRUE)
+ ? _IS_BOOL : Z_TYPE_P(o2);
+ if (Z_OBJ_HT_P(o1)->cast_object(Z_OBJ_P(o1), &casted, target_type) == FAILURE) {
+ // TODO: Less crazy.
+ if (target_type == IS_LONG || target_type == IS_DOUBLE) {
+ zend_error(E_NOTICE, "Object of class %s could not be converted to %s",
+ ZSTR_VAL(Z_OBJCE_P(o1)->name), zend_get_type_by_const(target_type));
+ if (target_type == IS_LONG) {
+ ZVAL_LONG(&casted, 1);
} else {
- return 1;
+ ZVAL_DOUBLE(&casted, 1.0);
}
+ } else {
+ return 1;
}
- int ret = zend_compare(&casted, o2);
- zval_ptr_dtor(&casted);
- return ret;
}
+ int ret = zend_compare(&casted, o2);
+ zval_ptr_dtor(&casted);
+ return ret;
} else {
ZEND_ASSERT(Z_TYPE_P(o2) == IS_OBJECT);
- if (Z_OBJ_HT_P(o2)->cast_object) {
- zend_uchar target_type = (Z_TYPE_P(o1) == IS_FALSE || Z_TYPE_P(o1) == IS_TRUE)
- ? _IS_BOOL : Z_TYPE_P(o1);
- if (Z_OBJ_HT_P(o2)->cast_object(Z_OBJ_P(o2), &casted, target_type) == FAILURE) {
- // TODO: Less crazy.
- if (target_type == IS_LONG || target_type == IS_DOUBLE) {
- zend_error(E_NOTICE, "Object of class %s could not be converted to %s",
- ZSTR_VAL(Z_OBJCE_P(o2)->name), zend_get_type_by_const(target_type));
- if (target_type == IS_LONG) {
- ZVAL_LONG(&casted, 1);
- } else {
- ZVAL_DOUBLE(&casted, 1.0);
- }
+ zend_uchar target_type = (Z_TYPE_P(o1) == IS_FALSE || Z_TYPE_P(o1) == IS_TRUE)
+ ? _IS_BOOL : Z_TYPE_P(o1);
+ if (Z_OBJ_HT_P(o2)->cast_object(Z_OBJ_P(o2), &casted, target_type) == FAILURE) {
+ // TODO: Less crazy.
+ if (target_type == IS_LONG || target_type == IS_DOUBLE) {
+ zend_error(E_NOTICE, "Object of class %s could not be converted to %s",
+ ZSTR_VAL(Z_OBJCE_P(o2)->name), zend_get_type_by_const(target_type));
+ if (target_type == IS_LONG) {
+ ZVAL_LONG(&casted, 1);
} else {
- return -1;
+ ZVAL_DOUBLE(&casted, 1.0);
}
+ } else {
+ return -1;
}
- int ret = zend_compare(o1, &casted);
- zval_ptr_dtor(&casted);
- return ret;
}
+ int ret = zend_compare(o1, &casted);
+ zval_ptr_dtor(&casted);
+ return ret;
}
return ZEND_UNCOMPARABLE;
}