# help request: passing return value

- Thread: https://externals.io/message/4714
- Original archive: https://news-web.php.net/php.internals/4714
- Started by netcat on 2003-10-07T08:43:45+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4714 — netcat — 2003-10-07T08:43:45+00:00

URL: https://externals.io/message/4714#4714

Hi internals.

[background]
I'm newbie here and with php extensions.
Working on php extension.
It should give access to librep.
I have very little experience with C.

[problem]

zval f1(some_args) {
  zval r;
  ...
  return r;
}

/* f1 can return many different types */

ZEND_FUNCTION(f2) {
  /* working on some_args here */
  ...
  ...
  /* here i need to return what
  f1(some_args) returns */
}

What's the best way to pass the result ?
Any macro that would ?
[tried]

To look at another modules.

Make f1 be (zval *) and
"*return_value=*rep_data_converter(result);"
in f2.
Since zval is not very simple structure - it doesn't work.


P.S.
  Posting this message to php.internals seems to fail.

-- 
NetCat


---------------------------------------------------
FREE 10MB Email + AntiSpam + POP3 + more.
Get it at http://www.doal.co.il:81/free/?c=antispam

---

## #4718 — Wez Furlong — 2003-10-07T10:15:18+00:00

URL: https://externals.io/message/4714#4718 · In reply to: #4714

PHP_FUNCTION (or ZEND_FUNCTION - they are the same)
includes the function paramters; one of those is:

zval *return_value;

which already contains an allocated zval (set to NULL).

If you want to change this in one of your own functions, you could
do something like this:

int f1(zval *return_value, ...)
{
    ... change the return_value here ...
   return SUCCESS;
}

PHP_FUNCTION(my_func)
{
    if (f1(return_value) == SUCCESS) {
        /* it worked */
        return;
    } else {
        /* it didn't work */
        php_error(....)
    }
}

Also take a look in Zend/zend.h at the definitions for
INTERNAL_FUNCTION_PARAMETERS and
INTERNAL_FUNCTION_PARAM_PASSTHRU
which can be used in you own function declarations to handle
the php function paramters.

Hope that helps,

--Wez.

PS: You're welcome to join the PHP Extension Community Library,
or PECL, on pecl-dev@lists.php.net

----- Original Message ----- 
From: "netcat" <netcat@abox.co.il>
To: "PHP Development" <internals@lists.php.net>
Sent: Tuesday, October 07, 2003 9:43 AM
Subject: [PHP-DEV] help request: passing return value


> Hi internals.
> 
> [background]
> I'm newbie here and with php extensions.
> Working on php extension.
> It should give access to librep.
> I have very little experience with C.
> 
> [problem]
> 
> zval f1(some_args) {
>   zval r;
>   ...
>   return r;
> }
> 
> /* f1 can return many different types */
> 
> ZEND_FUNCTION(f2) {
>   /* working on some_args here */
>   ...
>   ...
>   /* here i need to return what
>   f1(some_args) returns */
> }
> 
> What's the best way to pass the result ?
> Any macro that would ?
> [tried]
> 
> To look at another modules.
> 
> Make f1 be (zval *) and
> "*return_value=*rep_data_converter(result);"
> in f2.
> Since zval is not very simple structure - it doesn't work.

---

## #4721 — netcat — 2003-10-07T12:41:59+00:00

URL: https://externals.io/message/4714#4721 · In reply to: #4718

Wez Furlong wrote:

>PHP_FUNCTION (or ZEND_FUNCTION - they are the same)
>includes the function paramters; one of those is:
>
>zval *return_value;
>
>which already contains an allocated zval (set to NULL).
>
>If you want to change this in one of your own functions, you could
>do something like this:
>
>int f1(zval *return_value, ...)
>{
>    ... change the return_value here ...
>   return SUCCESS;
>}
>
>PHP_FUNCTION(my_func)
>{
>    if (f1(return_value) == SUCCESS) {
>        /* it worked */
>        return;
>    } else {
>        /* it didn't work */
>        php_error(....)
>    }
>}
>
>  
>
Thanks a lot, it seems to work.

>Also take a look in Zend/zend.h at the definitions for
>INTERNAL_FUNCTION_PARAMETERS and
>INTERNAL_FUNCTION_PARAM_PASSTHRU
>  
>
I will. Thanks again.

>which can be used in you own function declarations to handle
>the php function paramters.
>
>Hope that helps,
>
>--Wez.
>
>PS: You're welcome to join the PHP Extension Community Library,
>or PECL, on pecl-dev@lists.php.net
>
>----- Original Message ----- 
>From: "netcat" <netcat@abox.co.il>
>To: "PHP Development" <internals@lists.php.net>
>Sent: Tuesday, October 07, 2003 9:43 AM
>Subject: [PHP-DEV] help request: passing return value
>
>
>  
>
> > […]
>
>  
>


-- 
NetCat




------------------------------------------------------
SPAM-Free 10mb Free email + Antivirus + POP3 + more...
Get it at http://www.doal.co.il:81/free/?c=all-spam
