# Undefined variables as extension args

- Thread: https://externals.io/message/2158
- Original archive: https://news-web.php.net/php.internals/2158
- Started by Hans Zaunere on 2003-06-04T14:26:31+00:00
- Messages: 2
- 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

---

## #2158 — Hans Zaunere — 2003-06-04T14:26:31+00:00

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

Hello,

Please forgive me if this question is redundant, but I've searched high and
low to no avail.

As a PHP extension, I'm writing a ZEND_FUNCTION(myfunc) that needs to accept
two variables from PHP land, fill in two values (longs) and then return `TRUE` 
or FALSE.  Briefly:


ZEND_FUNCTION(ncurses_getyx)
{
    zval *z_y,*z_x;

    if( ZEND_NUM_ARGS() != 2 )
        WRONG_PARAM_COUNT;

    if( zend_parse_parameters(2 TSRMLS_CC, "zz",&z_y,&z_x) == FAILURE )
        RETURN_FALSE;

    ZVAL_LONG(z_y,123);
    ZVAL_LONG(z_x,321);

    RETURN_TRUE;
}


So, simple enough, this works, called, for example, like so from PHP:

$myy = 0;
$myx = 0;
ncurses_getyx($myy,$myx);

However, when I don't initialize $myy and $myx to 0 in PHP, I get "Notice -
Undefined variable: " errors.  While I understand why it would happen, I'd
like my function to act, for instance, like `exec()`.  `exec()` will accept
arguments to fill in, and even if they've never been initialized anywhere, no
such notice will be thrown.  `getmxrr()` acts in a similar way.

I've looked at the code for both of these functions:

http://lxr.php.net/source/php4/ext/standard/exec.c#192
http://lxr.php.net/source/php4/ext/standard/dns.c#708

but cannot see anything significant that would incur such different behavior
from that of my function.  I've played around with zval_dtor(), which is used
in `exec()`, but still without any luck.  Any help is appreciated.

Hans

---

## #2163 — Wez Furlong — 2003-06-04T16:29:01+00:00

URL: https://externals.io/message/2158#2163 · In reply to: #2158

in the function table, you need to force those parameters to be passed
by reference.

PHP_FE(ncurses_getyx, first_and_second__args_force_ref)

For an example of this, take a look at the headers_sent function entry
in ext/standard/basic_functions.c

--Wez.



>
> Hello,
>
> Please forgive me if this question is redundant, but I've searched high and
> low to no avail.
>
> As a PHP extension, I'm writing a ZEND_FUNCTION(myfunc) that needs to accept
> two variables from PHP land, fill in two values (longs) and then return `TRUE` 
> or FALSE.  Briefly:
>
>
> ZEND_FUNCTION(ncurses_getyx)
> {
>     zval *z_y,*z_x;
>
>     if( ZEND_NUM_ARGS() != 2 )
>         WRONG_PARAM_COUNT;
>
>     if( zend_parse_parameters(2 TSRMLS_CC, "zz",&z_y,&z_x) == FAILURE )
>         RETURN_FALSE;
>
>     ZVAL_LONG(z_y,123);
>     ZVAL_LONG(z_x,321);
>
>     RETURN_TRUE;
> }
>
>
> So, simple enough, this works, called, for example, like so from PHP:
>
> $myy = 0;
> $myx = 0;
> ncurses_getyx($myy,$myx);
>
> However, when I don't initialize $myy and $myx to 0 in PHP, I get "Notice -
> Undefined variable: " errors.  While I understand why it would happen, I'd
> like my function to act, for instance, like `exec()`.  `exec()` will accept
> arguments to fill in, and even if they've never been initialized anywhere, no
> such notice will be thrown.  `getmxrr()` acts in a similar way.
>
> I've looked at the code for both of these functions:
>
> http://lxr.php.net/source/php4/ext/standard/exec.c#192
> http://lxr.php.net/source/php4/ext/standard/dns.c#708
>
> but cannot see anything significant that would incur such different behavior
> from that of my function.  I've played around with zval_dtor(), which is used
> in `exec()`, but still without any luck.  Any help is appreciated.
>
> Hans
