Creating PHP array from input parameters
| From: | Daniel Mcfarlin | Date: | Wed, 15 Dec 2004 08:11:43 +0000 |
| Subject: | Creating PHP array from input parameters | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-1729@lists.php.net to get a copy of this message | ||
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 inputparameters. 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]); } 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