Re: Creating PHP array from input parameters

From: Date: Wed, 15 Dec 2004 09:46:19 +0000
Subject: Re: Creating PHP array from input parameters
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-1730@lists.php.net to get a copy of this message
Daniel Mcfarlin wrote:
Hi All,
     I've read the documentation for array creation and I'm trying to develop an extension function that will return an array of its input
parameters. I've got the following code (error handling has been omitted) PHP_FUNCTION(function) { int num_args = ZEND_NUM_ARGS(); zval*** args = (zval***) ecalloc(num_args,sizeof(zval**)); zend_get_parameters_array_ex(num_args,args); array_init(return_value); int i=0; for(;i<num_args;i++) { add_index_zval(return_value,i,*args[i]);
probably have to zval_add_ref() to make sure it's not getting free'd Regards Alan
} efree(args); return; } It compiles fine but with the 4.3.9 codebase I'm getting strange behavior. For example, the first argument to the function doesn't seem to appear in the returned array. Additionally, I've had trouble getting arrays to insert properly into the returned array. Example: $arr1 = array(1,2,3,4); $ret_array = function(1,$arr1,3); Works just fine but replace it with $ret_array = function(1,array(1,2,3,4),3) and the second parameter, the array, doesn't show up when you print_r $ret_array. I would appreciate any insight or suggestions. Thanks in advance. -Daniel


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