DateTime call_user_function_ex

From: Date: Wed, 11 Jul 2007 11:40:04 +0000
Subject: DateTime call_user_function_ex
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4786@lists.php.net to get a copy of this message
Hi! I am having problems with DateTime object and call_user_function_ex. Simple php code: $dt->setDate(2007, 10, 15); $dt->setTime(11,11,11); echo $dt->format(DateTime::ISO8601); output: 2007-10-15T11:11:11+0000 And output for the same object passed to internal function: Monam31UTCUTC1110UTC::0th+00008601 I can not find any sensible valgrind report for this. And function implementation looks like this: static const gchar *string_from_datetime(zval *zvalue) { if(Z_TYPE_P(zvalue) != IS_OBJECT) { g_warning("Can not format ISO datetime string. Value is not an object"); return NULL; } /* Create params array and format ISO8601 compatible string */ zval *dt_params; MAKE_STD_ZVAL(dt_params); array_init(dt_params); add_index_string(dt_params, 0, (gchar *)"DateTime::ISO8601", 0); zval *f_format; MAKE_STD_ZVAL(f_format); ZVAL_STRING(f_format, "format", 0); /* Copy function arguments */ zval ***args = __copy_args(dt_params); /* TSRMSLS_FETCH(); */ /* Should be called here (required for CG macro ) */ zval *retval; call_user_function_ex(NULL, &zvalue, f_format, &retval, 1, args, 1, NULL TSRMLS_CC); efree(args); return (const gchar *)Z_STRVAL_P(retval); } http://www.php.net/manual/pl/zend.calling-user-functions.php This doc says I should destroy retval. Do I have to use it if I need to return string value? If yes, why do I have to copy it over again to another zval? And a function to copy parameters: static zval ***__copy_args(zval *args) { zval ***params = NULL; guint i; guint argc = 0; if(args != NULL) { argc = zend_hash_num_elements(Z_ARRVAL_P(args)); params = (zval ***)emalloc(argc * sizeof(zval **)); zend_hash_internal_pointer_reset(Z_ARRVAL_P(args)); for(i = 0; i < argc; i++) { zend_hash_get_current_data(Z_ARRVAL_P(args), (void **)&params[i]); zend_hash_move_forward(Z_ARRVAL_P(args)); } return params; } return NULL; } Any idea? Piotras

« previous php.pecl.dev (#4786) next »