Can't pass an array to call_user_function_ex()

From: Date: Fri, 29 Apr 2005 23:46:25 +0000
Subject: Can't pass an array to call_user_function_ex()
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2326@lists.php.net to get a copy of this message
Hello, I need to reverse sort an array received as a parameter in an extension function, but I'm having trouble trying to call rsort() from this function. Specifically, I'm not succeeding when trying to pass the array to call_user_function_ex(), so it always returns FALSE. I thought I should copy the array received from the extension function (in my case it's called wb_delete_items), but I couldn't find examples anywhere so I'm not sure. Here is the code: ZEND_FUNCTION(wb_delete_items) { LONG pwbo; zval *zitems; BOOL bRet = TRUE; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|z", &pwbo, &zitems) == FAILURE) return; if(!wbIsWBObj((void *)pwbo, TRUE)) RETURN_NULL() switch(zitems->type) { case IS_NULL: // Do nothing RETURN_BOOL(TRUE); break; case IS_LONG: // Delete an item case IS_BOOL: ((PWBOBJ)pwbo)->item = zitems->value.lval; RETURN_LONG(wbDeleteItems((PWBOBJ)pwbo, zitems->value.lval < 0)); break; case IS_ARRAY: { int i, nelem; HashTable *target_hash; zval **params[1]; zval **entry; zval *fname; zval *newarray; // Sort items MAKE_STD_ZVAL(fname); ZVAL_STRING(fname, "rsort", 1); // The following code doesn't work! MAKE_STD_ZVAL(newarray); params[0] = &newarray; *newarray = *zitems; zval_copy_ctor(newarray); // Call PHP function rsort() if(!call_user_function_ex(CG(function_table), NULL, fname, &return_value, 1, params, 0, NULL TSRMLS_CC)) { zend_error(E_WARNING, "Error sorting array in function %s()", get_active_function_name(TSRMLS_C)); RETURN_NULL(); } // Prepare to read items from zitem array target_hash = HASH_OF(zitems); if(!target_hash) RETURN_NULL(); nelem = zend_hash_num_elements(target_hash); zend_hash_internal_pointer_reset(target_hash); // Loop to read array items for(i = 0; i < nelem; i++) { if(zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) zend_error(E_WARNING, "Could not retrieve element %d from array in function %s()", i, get_active_function_name(TSRMLS_C)); ((PWBOBJ)pwbo)->item = (*entry)->value.lval; if(!wbDeleteItems((PWBOBJ)pwbo, FALSE)) bRet = FALSE; if(i < nelem - 1) zend_hash_move_forward(target_hash); } // ~for } RETURN_BOOL(bRet); case IS_STRING: // Invalid parameter case IS_DOUBLE: default: zend_error(E_WARNING, "Parameter 2 expected to be an integer or array in function %s()", get_active_function_name(TSRMLS_C)); RETURN_NULL(); } } Any help would be greatly appreciated. Thanks in advance. ------------------- Rubem Pechansky WinBinder - The native Windows binding for PHP http://winbinder.sourceforge.net/ Hypervisual - Advanced Design for IT http://hypervisual.com/

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