diff options
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r-- | Zend/zend_operators.c | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 7b25eb1d52..896f6dcbe1 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -568,19 +568,33 @@ try_again: case IS_ARRAY: zend_error(E_NOTICE, "Array to string conversion"); zval_ptr_dtor(op); - ZVAL_NEW_STR(op, zend_string_init("Array", sizeof("Array")-1, 0)); + ZVAL_INTERNED_STR(op, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED)); break; case IS_OBJECT: { - zval dst; - - convert_object_to_type(op, &dst, IS_STRING, convert_to_string); - zval_ptr_dtor(op); + zval tmp; - if (Z_TYPE(dst) == IS_STRING) { - ZVAL_COPY_VALUE(op, &dst); - } else { - ZVAL_NEW_STR(op, zend_string_init("Object", sizeof("Object")-1, 0)); + if (Z_OBJ_HT_P(op)->cast_object) { + if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING) == SUCCESS) { + zval_ptr_dtor(op); + ZVAL_COPY_VALUE(op, &tmp); + return; + } + } else if (Z_OBJ_HT_P(op)->get) { + zval *z = Z_OBJ_HT_P(op)->get(op, &tmp); + if (Z_TYPE_P(z) != IS_OBJECT) { + zend_string *str = zval_get_string(z); + zval_ptr_dtor(z); + zval_ptr_dtor(op); + ZVAL_STR(op, str); + return; + } + zval_ptr_dtor(z); } + if (!EG(exception)) { + zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name)); + } + zval_ptr_dtor(op); + ZVAL_EMPTY_STRING(op); break; } case IS_REFERENCE: @@ -591,6 +605,19 @@ try_again: } /* }}} */ +ZEND_API zend_bool ZEND_FASTCALL _try_convert_to_string(zval *op) +{ + if (Z_TYPE_P(op) != IS_STRING) { + zend_string *str = zval_get_string_func(op); + if (UNEXPECTED(EG(exception))) { + return 0; + } + zval_ptr_dtor(op); + ZVAL_STR(op, str); + } + return 1; +} + static void convert_scalar_to_array(zval *op) /* {{{ */ { HashTable *ht = zend_new_array(1); @@ -859,7 +886,7 @@ try_again: } case IS_ARRAY: zend_error(E_NOTICE, "Array to string conversion"); - return zend_string_init("Array", sizeof("Array")-1, 0); + return ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED); case IS_OBJECT: { zval tmp; if (Z_OBJ_HT_P(op)->cast_object) { @@ -875,7 +902,9 @@ try_again: } zval_ptr_dtor(z); } - zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name)); + if (!EG(exception)) { + zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name)); + } return ZSTR_EMPTY_ALLOC(); } case IS_REFERENCE: @@ -889,6 +918,16 @@ try_again: } /* }}} */ +ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */ +{ + zend_string *str = zval_get_string_func(op); + if (UNEXPECTED(EG(exception))) { + return NULL; + } + return str; +} +/* }}} */ + static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */ { if ((result == op1) && (result == op2)) { |