Convert zval array to char **

From: Date: Fri, 22 Jul 2005 15:57:25 +0000
Subject: Convert zval array to char **
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2636@lists.php.net to get a copy of this message
I finally got my extension to run. The original Lib HSBC sent me was not the right one. Once they sent me a newer version all worked. Now to make things a little easier, I would like to allow the PHP user to send an array that I need to convert to a char ** to send to the lib function. Using the Tutorial Part 2 from Zend I was able to go from the zval array to char * pretty easily. No my issue is that the lib function expects it to be sent as a char **. I thought passing a reference to the char * would work, but it does not give the expected results. I tried creating an array of char * and copying the char * into position 0 of the array and that does not give the expected results either. Can anyone tell me how I would get this char * to become a char **? The header of the function I am using is:
          extern CcExport char *GenerateHash( char **params, const char *key );
It normally would expect params to be from standard inputs argv. Here is the code: PHP_FUNCTION(hsbc_cpi_make_hash) { char *strEncryptedKey; int strEncryptedKey_len; zval *arr, **data; HashTable *arr_hash; HashPosition pointer; char *ppHashElements; char *strHashValue; int rc=0; int array_count; int count = 0; int bcount = 0; if ( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "as", &arr, &strEncryptedKey, &strEncryptedKey_len) == FAILURE ) { RETURN_NULL();
    }
arr_hash = Z_ARRVAL_P(arr); array_count = zend_hash_num_elements(arr_hash); ppHashElements = malloc(2048); if(!ppHashElements){ RETURN_NULL(); } memset(ppHashElements, 0, 2048); for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)){ count++; zval temp; temp = **data; zval_copy_ctor(&temp); convert_to_string(&temp);
       strcat(ppHashElements, Z_STRVAL(temp));
       if(count < array_count){
           strcat(ppHashElements, ", ");
       }
zval_dtor(&temp); } strHashValue = GenerateHash(&ppHashElements, strEncryptedKey ); php_printf("%s\n", strEncryptedKey); php_printf("%s\n", strHashValue); php_printf("%s\n", ppHashElements); free(ppHashElements); if(!strHashValue){
       RETURN_FALSE;
} RETURN_STRING(strHashValue, 1); }

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