diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-31 12:17:32 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-31 14:37:49 +0200 |
commit | 8fd7f02ea4cd595a792ef37e558d357d97bceefa (patch) | |
tree | a4684263d41cf407f5cffb725fe319bbc05da75c /Zend/zend_operators.c | |
parent | 36935e42eac054a422b7edade69923db7727f268 (diff) | |
download | php-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_operators.c')
-rw-r--r-- | Zend/zend_operators.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 600aad7bb7..f90b4ca377 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -137,13 +137,11 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* { /* {{{ convert_object_to_type: dst will be either ctype or UNDEF */ #define convert_object_to_type(op, dst, ctype, conv_func) \ ZVAL_UNDEF(dst); \ - if (Z_OBJ_HT_P(op)->cast_object) { \ - if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \ - zend_error(E_NOTICE, \ - "Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\ - zend_get_type_by_const(ctype)); \ - } \ - } + if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \ + zend_error(E_NOTICE, \ + "Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\ + zend_get_type_by_const(ctype)); \ + } \ /* }}} */ @@ -565,13 +563,10 @@ try_again: break; case IS_OBJECT: { zval tmp; - - if (Z_OBJ_HT_P(op)->cast_object) { - if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) { - zval_ptr_dtor(op); - ZVAL_COPY_VALUE(op, &tmp); - return; - } + if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) { + zval_ptr_dtor(op); + ZVAL_COPY_VALUE(op, &tmp); + return; } if (!EG(exception)) { zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name)); @@ -874,10 +869,8 @@ try_again: NULL : ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED); case IS_OBJECT: { zval tmp; - if (Z_OBJ_HT_P(op)->cast_object) { - if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) { - return Z_STR(tmp); - } + if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) { + return Z_STR(tmp); } if (!EG(exception)) { zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name)); @@ -2422,14 +2415,11 @@ ZEND_API int ZEND_FASTCALL zend_is_true(zval *op) /* {{{ */ ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op) /* {{{ */ { zend_object *zobj = Z_OBJ_P(op); - - if (zobj->handlers->cast_object) { - zval tmp; - if (zobj->handlers->cast_object(zobj, &tmp, _IS_BOOL) == SUCCESS) { - return Z_TYPE(tmp) == IS_TRUE; - } - zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(zobj->ce->name)); + zval tmp; + if (zobj->handlers->cast_object(zobj, &tmp, _IS_BOOL) == SUCCESS) { + return Z_TYPE(tmp) == IS_TRUE; } + zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(zobj->ce->name)); return 1; } /* }}} */ |