[PHP-DEV] Return array in parameter from extension

2002-09-24 Thread Ole Stakemann

Hi

This is probably a stupid question, but I can't figure it out. I've 
been trying to search the PHP site for an answer without luck.

I want to return results in an array from an extension. The array may 
or may not be defined. The array may or may not contain values. The 
PHP function could be something like

function modarray($inoutarray)
{
if (!isset($inoutarray))
{
$inoutarray = array();
}
$inoutarray[] = newval1;
$inoutarray[] = newval2;
}

How do I do that in an extension? I want to adhere to the 
recommendation that allow_call_time_pass_reference should be off.

-Ole

-- 
__
Konsulentfirmaet Ole Stakemann ApS
Fortunvej 55
DK-2920  Charlottenlund
Denmark

e-mail: [EMAIL PROTECTED]
Phone: +45 39 64 10 68
Fax: +45 39 64 10 67

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Return array in parameter from extension

2002-09-24 Thread Brian France

Try this:

/*** array your_ext_func() ***/
ZEND_FUNCTION(your_ext_func)
{
zval *val_ret, *val_str;
char *output;
int ret;

output = (char *)emalloc( 100 );

some code to set output and ret

array_init(return_value);
MAKE_STD_ZVAL(val_ret);
MAKE_STD_ZVAL(val_str);

ZVAL_LONG(val_ret, ret );
ZVAL_STRING(val_str, output, 0);

/*** return_value is an array, [0] is value ret, [1] is 
string output ***/
zend_hash_next_index_insert( HASH_OF(return_value), val_ret, 
sizeof(zval *), NULL );
zend_hash_next_index_insert( HASH_OF(return_value), val_str, 
sizeof(zval *), NULL );
}


In your php file do this:

list($ret,$str) =  your_ext_func();

Just a simple example, edit as needed.

Brian

At 6:21 PM +0200 9/24/02, Ole Stakemann wrote:
How do I do that in an extension? I want to adhere to the 
recommendation that allow_call_time_pass_reference should be off.

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php