Hi Marcus, This is improved version of your patch. It breaks only two tests those must be changed. (instead of > 10 those shouldn't) Please review.
Thanks. Dmitry. > -----Original Message----- > From: Marcus Boerger [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 25, 2005 4:37 PM > To: internals > Subject: [PHP-DEV] [PATCH] __toString() > > > Hello internals, > > the patch implements __toString to have obejcts be > automatically converted to strings anywhere a string is > requested. We have talked a lot about this in the past and > during OSCON Andi agreed again on it and said that the HEAD > version of the engine should be ready for it now. Futher more > we have enough time to fix any outstanding engine issues > regarding this. > > http://php.net/~helly/php/ext/ze2/ze2-tostring-20050925.diff.txt > > If nobody objects with a real technical issue i'll commit > the patch early in the week. > > The patch is a little big longer because it ensures that > __toString gets treated and especially gets cached just like > any other magic function is. > > Best regards, > Marcus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
? Zend/! ? Zend/1 ? Zend/NEW_API ? Zend/zend_API.h.my ? Zend/tests/bug33512.phpt ? Zend/tests/bug34062.phpt Index: Zend/zend.c =================================================================== RCS file: /repository/ZendEngine2/zend.c,v retrieving revision 1.323 diff -u -p -d -r1.323 zend.c --- Zend/zend.c 15 Sep 2005 16:19:41 -0000 1.323 +++ Zend/zend.c 26 Sep 2005 12:13:12 -0000 @@ -347,39 +347,28 @@ ZEND_API void zend_make_string_zval(zval case IS_OBJECT: { TSRMLS_FETCH(); -#if 0 - /* Standard PHP objects */ - if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HT_P(expr)->cast_object) { - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - break; - } - zend_error(E_NOTICE, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name); - } -#endif if (Z_OBJ_HANDLER_P(expr, cast_object)) { if(Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { break; } - } else { - if(Z_OBJ_HANDLER_P(expr, get)) { - zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); - if(Z_TYPE_P(z) != IS_OBJECT) { - zend_make_printable_zval(z, expr_copy, use_copy); - FREE_ZVAL(z); - return; - } + } + if (Z_OBJ_HANDLER_P(expr, get)) { + zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); + if(Z_TYPE_P(z) != IS_OBJECT) { + zend_make_printable_zval(z, expr_copy, use_copy); + FREE_ZVAL(z); + break; } } if (EG(exception)) { - zval_dtor(expr_copy); expr_copy->value.str.len = 0; expr_copy->value.str.val = STR_EMPTY_ALLOC(); break; } + } expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG); expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle); - expr_copy->type = IS_STRING; break; default: *expr_copy = *expr; @@ -387,6 +376,7 @@ ZEND_API void zend_make_string_zval(zval convert_to_string(expr_copy); break; } + expr_copy->type = IS_STRING; *use_copy = 1; } @@ -426,40 +416,26 @@ ZEND_API void zend_make_printable_zval(z expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len); break; case IS_OBJECT: - { -#if 0 - /* Standard PHP objects */ - if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HT_P(expr)->cast_object) { - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - break; - } - zend_error(E_NOTICE, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name); - } -#endif - if (Z_OBJ_HANDLER_P(expr, cast_object)) { - if(Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - break; - } - } else { - if(Z_OBJ_HANDLER_P(expr, get)) { - zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); - if(Z_TYPE_P(z) != IS_OBJECT) { - zend_make_printable_zval(z, expr_copy, use_copy); - FREE_ZVAL(z); - return; - } - } + if (Z_OBJ_HANDLER_P(expr, cast_object)) { + if(Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { + break; } - if (EG(exception)) { - zval_dtor(expr_copy); - expr_copy->value.str.len = 0; - expr_copy->value.str.val = STR_EMPTY_ALLOC(); + } + if (Z_OBJ_HANDLER_P(expr, get)) { + zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); + if(Z_TYPE_P(z) != IS_OBJECT) { + zend_make_printable_zval(z, expr_copy, use_copy); + FREE_ZVAL(z); break; } } + if (EG(exception)) { + expr_copy->value.str.len = 0; + expr_copy->value.str.val = STR_EMPTY_ALLOC(); + break; + } expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG); expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle); - expr_copy->type = IS_STRING; break; case IS_DOUBLE: *expr_copy = *expr; @@ -491,40 +467,26 @@ ZEND_API void zend_make_unicode_zval(zva } switch (expr->type) { case IS_OBJECT: - { -#if 0 - /* Standard PHP objects */ - if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HT_P(expr)->cast_object) { - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - break; - } - zend_error(E_NOTICE, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name); - } -#endif - if (Z_OBJ_HANDLER_P(expr, cast_object)) { - if(Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_UNICODE, 0 TSRMLS_CC) == SUCCESS) { - break; - } - } else { - if(Z_OBJ_HANDLER_P(expr, get)) { - zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); - if(Z_TYPE_P(z) != IS_OBJECT) { - zend_make_unicode_zval(z, expr_copy, use_copy); - FREE_ZVAL(z); - return; - } - } + if (Z_OBJ_HANDLER_P(expr, cast_object)) { + if(Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_UNICODE, 0 TSRMLS_CC) == SUCCESS) { + break; } - if (EG(exception)) { - zval_dtor(expr_copy); - expr_copy->value.ustr.len = 0; - expr_copy->value.ustr.val = USTR_MAKE(""); + } + if (Z_OBJ_HANDLER_P(expr, get)) { + zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); + if(Z_TYPE_P(z) != IS_OBJECT) { + zend_make_unicode_zval(z, expr_copy, use_copy); + FREE_ZVAL(z); break; } } - expr_copy->value.ustr.val = emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG + 1); + if (EG(exception)) { + expr_copy->value.ustr.len = 0; + expr_copy->value.ustr.val = USTR_MAKE(""); + break; + } + expr_copy->value.ustr.val = eumalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG + 1); expr_copy->value.ustr.len = u_sprintf(expr_copy->value.ustr.val, "Object id #%ld", (long)expr->value.obj.handle); - expr_copy->type = IS_UNICODE; break; default: *expr_copy = *expr; @@ -532,6 +494,7 @@ ZEND_API void zend_make_unicode_zval(zva convert_to_unicode(expr_copy); break; } + expr_copy->type = IS_UNICODE; *use_copy = 1; } @@ -969,6 +932,8 @@ static void fix_classes(HashTable *ht) { ce->__isset = ce->__isset->common.u_twin; } else if (ce->__call) { ce->__call = ce->__call->common.u_twin; + } else if (ce->__tostring) { + ce->__tostring = ce->__tostring->common.u_twin; } else if (ce->serialize_func) { ce->serialize_func = ce->serialize_func->common.u_twin; } else if (ce->unserialize_func) { Index: Zend/zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.299 diff -u -p -d -r1.299 zend.h --- Zend/zend.h 1 Sep 2005 10:04:54 -0000 1.299 +++ Zend/zend.h 26 Sep 2005 12:13:13 -0000 @@ -360,6 +360,7 @@ struct _zend_class_entry { union _zend_function *__unset; union _zend_function *__isset; union _zend_function *__call; + union _zend_function *__tostring; union _zend_function *serialize_func; union _zend_function *unserialize_func; Index: Zend/zend_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_API.c,v retrieving revision 1.315 diff -u -p -d -r1.315 zend_API.c --- Zend/zend_API.c 1 Sep 2005 10:04:55 -0000 1.315 +++ Zend/zend_API.c 26 Sep 2005 12:13:16 -0000 @@ -2022,6 +2022,9 @@ ZEND_API void zend_check_magic_method_im } else if (lcname_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && ZEND_U_EQUAL(utype, lcname, lcname_len, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1) && fptr->common.num_args != 2) { zend_error(error_type, "Method %v::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME); + } else if (lcname_len == sizeof(ZEND_TOSTRING_FUNC_NAME) - 1 && + ZEND_U_EQUAL(utype, lcname, lcname_len, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && fptr->common.num_args != 0) { + zend_error(error_type, "Method %v::%s() cannot take arguments", ce->name, ZEND_CALL_FUNC_NAME); } efree(lcname); } @@ -2035,7 +2038,7 @@ ZEND_API int zend_register_functions(zen int count=0, unload=0; HashTable *target_function_table = function_table; int error_type; - zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL; + zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__tostring = NULL; char *lowercase_name; int fname_len; char *lc_class_name; @@ -2139,6 +2142,8 @@ ZEND_API int zend_register_functions(zen clone = reg_function; } else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) { __call = reg_function; + } else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME))) { + __tostring = reg_function; } else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) { __get = reg_function; } else if ((fname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) { @@ -2176,6 +2181,7 @@ ZEND_API int zend_register_functions(zen scope->destructor = dtor; scope->clone = clone; scope->__call = __call; + scope->__tostring = __tostring; scope->__get = __get; scope->__set = __set; scope->__unset = __unset; @@ -2207,6 +2213,12 @@ ZEND_API int zend_register_functions(zen } __call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC; } + if (__tostring) { + if (__tostring->common.fn_flags & ZEND_ACC_STATIC) { + zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __tostring->common.function_name); + } + __tostring->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC; + } if (__get) { if (__get->common.fn_flags & ZEND_ACC_STATIC) { zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __get->common.function_name); Index: Zend/zend_API.h =================================================================== RCS file: /repository/ZendEngine2/zend_API.h,v retrieving revision 1.221 diff -u -p -d -r1.221 zend_API.h --- Zend/zend_API.h 23 Sep 2005 22:49:57 -0000 1.221 +++ Zend/zend_API.h 26 Sep 2005 12:13:17 -0000 @@ -131,6 +131,7 @@ typedef struct _zend_function_entry { class_container.create_object = NULL; \ class_container.interface_gets_implemented = NULL; \ class_container.__call = handle_fcall; \ + class_container.__tostring = NULL; \ class_container.__get = handle_propget; \ class_container.__set = handle_propset; \ class_container.__unset = handle_propunset; \ Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.663 diff -u -p -d -r1.663 zend_compile.c --- Zend/zend_compile.c 16 Sep 2005 13:42:31 -0000 1.663 +++ Zend/zend_compile.c 26 Sep 2005 12:13:25 -0000 @@ -1163,6 +1163,8 @@ void zend_do_begin_function_declaration( CG(active_class_entry)->__unset = (zend_function *) CG(active_op_array); } else if ((lcname_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { CG(active_class_entry)->__isset = (zend_function *) CG(active_op_array); + } else if ((lcname_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { + CG(active_class_entry)->__tostring = (zend_function *) CG(active_op_array); } else if (!(fn_flags & ZEND_ACC_STATIC)) { CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC; } @@ -1873,6 +1875,9 @@ static void do_inherit_parent_constructo if (!ce->__call) { ce->__call = ce->parent->__call; } + if (!ce->__tostring) { + ce->__tostring = ce->parent->__tostring; + } if (!ce->clone) { ce->clone = ce->parent->clone; } @@ -4152,6 +4157,7 @@ ZEND_API void zend_initialize_class_data ce->__unset = NULL; ce->__isset = NULL; ce->__call = NULL; + ce->__tostring = NULL; ce->create_object = NULL; ce->get_iterator = NULL; ce->iterator_funcs.funcs = NULL; Index: Zend/zend_compile.h =================================================================== RCS file: /repository/ZendEngine2/zend_compile.h,v retrieving revision 1.324 diff -u -p -d -r1.324 zend_compile.h --- Zend/zend_compile.h 23 Sep 2005 22:55:10 -0000 1.324 +++ Zend/zend_compile.h 26 Sep 2005 12:13:26 -0000 @@ -723,6 +723,7 @@ END_EXTERN_C() #define ZEND_UNSET_FUNC_NAME "__unset" #define ZEND_ISSET_FUNC_NAME "__isset" #define ZEND_CALL_FUNC_NAME "__call" +#define ZEND_TOSTRING_FUNC_NAME "__tostring" #define ZEND_AUTOLOAD_FUNC_NAME "__autoload" #endif /* ZEND_COMPILE_H */ Index: Zend/zend_object_handlers.c =================================================================== RCS file: /repository/ZendEngine2/zend_object_handlers.c,v retrieving revision 1.146 diff -u -p -d -r1.146 zend_object_handlers.c --- Zend/zend_object_handlers.c 1 Sep 2005 10:05:00 -0000 1.146 +++ Zend/zend_object_handlers.c 26 Sep 2005 12:13:27 -0000 @@ -1008,37 +1008,30 @@ int zend_std_object_get_class_name(zval ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) { - zval fname, *retval; + zval *retval; + zend_class_entry *ce; switch (type) { case IS_STRING: case IS_UNICODE: - if (!zend_hash_exists(&Z_OBJCE_P(readobj)->function_table, "__tostring", sizeof("__tostring"))) { - return FAILURE; - } - ZVAL_ASCII_STRING(&fname, "__tostring", 0); - if (call_user_function_ex(NULL, &readobj, &fname, &retval, 0, NULL, 0, NULL TSRMLS_CC) == SUCCESS) { - if (UG(unicode)) { - zval_dtor(&fname); - } - if (retval) { - if (Z_TYPE_P(retval) != (UG(unicode)?IS_UNICODE:IS_STRING)) { - zend_error(E_ERROR, "Method %v::__toString() must return a string value", Z_OBJCE_P(readobj)->name); + ce = Z_OBJCE_P(readobj); + if (ce->__tostring && + zend_call_method_with_0_params(&readobj, ce, &ce->__tostring, "__tostring", &retval)) { + if (Z_TYPE_P(retval) == (UG(unicode)?IS_UNICODE:IS_STRING)) { + *writeobj = *retval; + zval_copy_ctor(writeobj); + zval_ptr_dtor(&retval); + INIT_PZVAL(writeobj); + if (Z_TYPE_P(writeobj) != type) { + convert_to_explicit_type(writeobj, type); } + return SUCCESS; } else { - MAKE_STD_ZVAL(retval); - ZVAL_ASCII_STRINGL(retval, "", 0, 1); + zval_ptr_dtor(&retval); + zend_error(E_RECOVERABLE_ERROR, "Method %v::__toString() must return a string value", ce->name); } - *writeobj = *retval; - zval_copy_ctor(writeobj); - INIT_PZVAL(writeobj); - zval_ptr_dtor(&retval); - return SUCCESS; - } - if (UG(unicode)) { - zval_dtor(&fname); } - break; + return FAILURE; default: break; } @@ -1069,7 +1062,7 @@ ZEND_API zend_object_handlers std_object zend_std_object_get_class, /* get_class_entry */ zend_std_object_get_class_name, /* get_class_name */ zend_std_compare_objects, /* compare_objects */ - NULL, /* cast_object */ + zend_std_cast_object_tostring, /* cast_object */ NULL, /* count_elements */ }; Index: Zend/zend_vm_def.h =================================================================== RCS file: /repository/ZendEngine2/zend_vm_def.h,v retrieving revision 1.79 diff -u -p -d -r1.79 zend_vm_def.h --- Zend/zend_vm_def.h 23 Sep 2005 09:38:36 -0000 1.79 +++ Zend/zend_vm_def.h 26 Sep 2005 12:13:31 -0000 @@ -884,34 +884,28 @@ ZEND_VM_HANDLER(40, ZEND_ECHO, CONST|TMP zend_free_op free_op1; zval z_copy; zval *z = GET_OP1_ZVAL_PTR(BP_VAR_R); + UErrorCode status = U_ZERO_ERROR; - if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, UG(unicode) ? IS_UNICODE : IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); - } else { - UErrorCode status = U_ZERO_ERROR; - /* Convert inline HTML blocks to the output encoding, but only if necessary. */ - if (opline->extended_value && - strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { - zval z_conv; - UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); - } - zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); - z_conv.type = IS_BINARY; - if (U_SUCCESS(status)) { - zend_print_variable(&z_conv); - } else { - zend_error(E_WARNING, "Could not convert inline HTML for output"); - } - zval_dtor(&z_conv); - ucnv_close(script_enc_conv); + /* Convert inline HTML blocks to the output encoding, but only if necessary. */ + if (opline->extended_value && + strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), + EG(active_op_array)->script_encoding)) { + zval z_conv; + UConverter *script_enc_conv = NULL; + if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + } + zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); + z_conv.type = IS_BINARY; + if (U_SUCCESS(status)) { + zend_print_variable(&z_conv); } else { - zend_print_variable(z); + zend_error(E_WARNING, "Could not convert inline HTML for output"); } + zval_dtor(&z_conv); + ucnv_close(script_enc_conv); + } else { + zend_print_variable(z); } FREE_OP1(); Index: Zend/zend_vm_execute.h =================================================================== RCS file: /repository/ZendEngine2/zend_vm_execute.h,v retrieving revision 1.82 diff -u -p -d -r1.82 zend_vm_execute.h --- Zend/zend_vm_execute.h 23 Sep 2005 09:38:35 -0000 1.82 +++ Zend/zend_vm_execute.h 26 Sep 2005 12:13:46 -0000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.82 2005/09/23 09:38:35 tony2001 Exp $ */ +/* $Id: zend_vm_gen.php,v 1.13 2005/08/11 23:35:03 andrei Exp $ */ static opcode_handler_t zend_user_opcode_handlers[256] = {(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL}; @@ -1367,34 +1367,28 @@ static int ZEND_ECHO_SPEC_CONST_HANDLER( zval z_copy; zval *z = &opline->op1.u.constant; + UErrorCode status = U_ZERO_ERROR; - if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, UG(unicode) ? IS_UNICODE : IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); - } else { - UErrorCode status = U_ZERO_ERROR; - /* Convert inline HTML blocks to the output encoding, but only if necessary. */ - if (opline->extended_value && - strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { - zval z_conv; - UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); - } - zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); - z_conv.type = IS_BINARY; - if (U_SUCCESS(status)) { - zend_print_variable(&z_conv); - } else { - zend_error(E_WARNING, "Could not convert inline HTML for output"); - } - zval_dtor(&z_conv); - ucnv_close(script_enc_conv); + /* Convert inline HTML blocks to the output encoding, but only if necessary. */ + if (opline->extended_value && + strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), + EG(active_op_array)->script_encoding)) { + zval z_conv; + UConverter *script_enc_conv = NULL; + if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + } + zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); + z_conv.type = IS_BINARY; + if (U_SUCCESS(status)) { + zend_print_variable(&z_conv); } else { - zend_print_variable(z); + zend_error(E_WARNING, "Could not convert inline HTML for output"); } + zval_dtor(&z_conv); + ucnv_close(script_enc_conv); + } else { + zend_print_variable(z); } ZEND_VM_NEXT_OPCODE(); @@ -3879,34 +3873,28 @@ static int ZEND_ECHO_SPEC_TMP_HANDLER(ZE zend_free_op free_op1; zval z_copy; zval *z = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); + UErrorCode status = U_ZERO_ERROR; - if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, UG(unicode) ? IS_UNICODE : IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); - } else { - UErrorCode status = U_ZERO_ERROR; - /* Convert inline HTML blocks to the output encoding, but only if necessary. */ - if (opline->extended_value && - strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { - zval z_conv; - UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); - } - zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); - z_conv.type = IS_BINARY; - if (U_SUCCESS(status)) { - zend_print_variable(&z_conv); - } else { - zend_error(E_WARNING, "Could not convert inline HTML for output"); - } - zval_dtor(&z_conv); - ucnv_close(script_enc_conv); + /* Convert inline HTML blocks to the output encoding, but only if necessary. */ + if (opline->extended_value && + strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), + EG(active_op_array)->script_encoding)) { + zval z_conv; + UConverter *script_enc_conv = NULL; + if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + } + zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); + z_conv.type = IS_BINARY; + if (U_SUCCESS(status)) { + zend_print_variable(&z_conv); } else { - zend_print_variable(z); + zend_error(E_WARNING, "Could not convert inline HTML for output"); } + zval_dtor(&z_conv); + ucnv_close(script_enc_conv); + } else { + zend_print_variable(z); } zval_dtor(free_op1.var); @@ -6930,34 +6918,28 @@ static int ZEND_ECHO_SPEC_VAR_HANDLER(ZE zend_free_op free_op1; zval z_copy; zval *z = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); + UErrorCode status = U_ZERO_ERROR; - if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, UG(unicode) ? IS_UNICODE : IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); - } else { - UErrorCode status = U_ZERO_ERROR; - /* Convert inline HTML blocks to the output encoding, but only if necessary. */ - if (opline->extended_value && - strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { - zval z_conv; - UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); - } - zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); - z_conv.type = IS_BINARY; - if (U_SUCCESS(status)) { - zend_print_variable(&z_conv); - } else { - zend_error(E_WARNING, "Could not convert inline HTML for output"); - } - zval_dtor(&z_conv); - ucnv_close(script_enc_conv); + /* Convert inline HTML blocks to the output encoding, but only if necessary. */ + if (opline->extended_value && + strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), + EG(active_op_array)->script_encoding)) { + zval z_conv; + UConverter *script_enc_conv = NULL; + if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + } + zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); + z_conv.type = IS_BINARY; + if (U_SUCCESS(status)) { + zend_print_variable(&z_conv); } else { - zend_print_variable(z); + zend_error(E_WARNING, "Could not convert inline HTML for output"); } + zval_dtor(&z_conv); + ucnv_close(script_enc_conv); + } else { + zend_print_variable(z); } if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -19709,34 +19691,28 @@ static int ZEND_ECHO_SPEC_CV_HANDLER(ZEN zval z_copy; zval *z = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); + UErrorCode status = U_ZERO_ERROR; - if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, UG(unicode) ? IS_UNICODE : IS_STRING, 0 TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); - } else { - UErrorCode status = U_ZERO_ERROR; - /* Convert inline HTML blocks to the output encoding, but only if necessary. */ - if (opline->extended_value && - strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { - zval z_conv; - UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); - } - zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); - z_conv.type = IS_BINARY; - if (U_SUCCESS(status)) { - zend_print_variable(&z_conv); - } else { - zend_error(E_WARNING, "Could not convert inline HTML for output"); - } - zval_dtor(&z_conv); - ucnv_close(script_enc_conv); + /* Convert inline HTML blocks to the output encoding, but only if necessary. */ + if (opline->extended_value && + strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), + EG(active_op_array)->script_encoding)) { + zval z_conv; + UConverter *script_enc_conv = NULL; + if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + } + zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); + z_conv.type = IS_BINARY; + if (U_SUCCESS(status)) { + zend_print_variable(&z_conv); } else { - zend_print_variable(z); + zend_error(E_WARNING, "Could not convert inline HTML for output"); } + zval_dtor(&z_conv); + ucnv_close(script_enc_conv); + } else { + zend_print_variable(z); } ZEND_VM_NEXT_OPCODE(); Index: Zend/zend_vm_opcodes.h =================================================================== RCS file: /repository/ZendEngine2/zend_vm_opcodes.h,v retrieving revision 1.59 diff -u -p -d -r1.59 zend_vm_opcodes.h --- Zend/zend_vm_opcodes.h 23 Sep 2005 09:38:37 -0000 1.59 +++ Zend/zend_vm_opcodes.h 26 Sep 2005 12:13:46 -0000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.59 2005/09/23 09:38:37 tony2001 Exp $ */ +/* $Id: zend_vm_gen.php,v 1.13 2005/08/11 23:35:03 andrei Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php