# allow extension writers to ignore E_NOTICE warnings about unset variables

- Thread: https://externals.io/message/23285
- Original archive: https://news-web.php.net/php.internals/23285
- Started by D. Dante Lorenso on 2006-05-11T22:49:45+00:00
- Messages: 8
- 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

---

## #23285 — D. Dante Lorenso — 2006-05-11T22:49:45+00:00

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

All,

Is there a way to define a function in an extension which would not 
require a passed in variable to exist?  In other words, can ZE be 
modified to allow extensions to not trigger `E_NOTICE` warnings if an 
unset variable is passed to a function which does not care if the var is 
set?

I can specify preferences about whether variables are passed by 
reference or not using macros like:

    * PHP_FE(..., first_arg_force_ref)
    * PHP_FE(..., third_arg_force_by_ref_rest)
    * PHP_FE(..., first_through_third_args_force_ref)

Which probably boil down somewhere into:

    * #define ZEND_SEND_BY_VAL     0
    * #define ZEND_SEND_BY_REF     1
    * #define ZEND_SEND_PREFER_REF 2

And I notice that if a variable is passed by reference to an extension 
function, no `E_NOTICE` is thrown.  Well, can we extend this concept 
further to say something like:

    * #define ZEND_SEND_WHO_CARES_IF_IT_EXISTS_OR_NOT 4

*but with a better name, of course*

Then, extension developers can write 'ifsetor', 'coalesce', and 'filled' 
as extensions (by themselves) and not need those specific functions 
added to the 'PHP core language' per-se.

Dante

---

## #23286 — Antony Dovgal — 2006-05-11T22:56:05+00:00

URL: https://externals.io/message/23285#23286 · In reply to: #23285

> All,
> 
> Is there a way to define a function in an extension which would not 
> require a passed in variable to exist?  In other words, can ZE be 
> modified to allow extensions to not trigger `E_NOTICE` warnings if an 
> unset variable is passed to a function which does not care if the var is 
> set?
> 
> I can specify preferences about whether variables are passed by 
> reference or not using macros like:
> 
>     * PHP_FE(..., first_arg_force_ref)
>     * PHP_FE(..., third_arg_force_by_ref_rest)
>     * PHP_FE(..., first_through_third_args_force_ref)
> 
> Which probably boil down somewhere into:
> 
>     * #define ZEND_SEND_BY_VAL     0
>     * #define ZEND_SEND_BY_REF     1

This one is what you need.

-- 
Wbr, 
Antony Dovgal

---

## #23287 — Marcus Boerger — 2006-05-11T22:56:34+00:00

URL: https://externals.io/message/23285#23287 · In reply to: #23285

Hello D.,

  no, the compiler generates code that makes the executor generate the
variable and complain prior to performing the call. In a zend extension
you could try to hook into that process.

marcus

Friday, May 12, 2006, 12:49:45 AM, you wrote:

> All,

> Is there a way to define a function in an extension which would not 
> require a passed in variable to exist?  In other words, can ZE be 
> modified to allow extensions to not trigger `E_NOTICE` warnings if an 
> unset variable is passed to a function which does not care if the var is 
> set?

> I can specify preferences about whether variables are passed by 
> reference or not using macros like:

>     * PHP_FE(..., first_arg_force_ref)
>     * PHP_FE(..., third_arg_force_by_ref_rest)
>     * PHP_FE(..., first_through_third_args_force_ref)

> Which probably boil down somewhere into:

>     * #define ZEND_SEND_BY_VAL     0
>     * #define ZEND_SEND_BY_REF     1
>     * #define ZEND_SEND_PREFER_REF 2

> And I notice that if a variable is passed by reference to an extension 
> function, no `E_NOTICE` is thrown.  Well, can we extend this concept 
> further to say something like:

>     * #define ZEND_SEND_WHO_CARES_IF_IT_EXISTS_OR_NOT 4

> *but with a better name, of course*

> Then, extension developers can write 'ifsetor', 'coalesce', and 'filled' 
> as extensions (by themselves) and not need those specific functions 
> added to the 'PHP core language' per-se.

> Dante




Best regards,
 Marcus

---

## #23288 — D. Dante Lorenso — 2006-05-11T23:05:30+00:00

URL: https://externals.io/message/23285#23288 · In reply to: #23286

Antony Dovgal wrote:
> 
> > […]
> This one is what you need.
I don't think it is.  The variable did not exist before the function was 
called and should STILL not exist afterwards.  I believe when you pass 
by reference, the variable will exist after the call.  This is bad since 
future calls to 'isset' will suddenly start returning `TRUE` when they 
shouldn't.

Dante

---

## #23292 — D. Dante Lorenso — 2006-05-11T23:10:41+00:00

URL: https://externals.io/message/23285#23292 · In reply to: #23287

Marcus Boerger wrote:
> no, the compiler generates code that makes the executor generate the
> variable and complain prior to performing the call.
>   

The executor doesn't complain about unset variables prior to calling 
functions by reference, so I was thinking it could be modified to also 
not complain when calling functions that don't care about set 
variables.  Naturally, the unset variable would evaluate as `NULL` and be 
passed as such, just there would be no E_NOTICE.

> In a zend extension you could try to hook into that process.
>   

How do you mean?  Got any pointers?


Dante

---

## #23289 — Marcus Boerger — 2006-05-11T23:21:08+00:00

URL: https://externals.io/message/23285#23289 · In reply to: #23292

Hello D.,

Friday, May 12, 2006, 1:10:41 AM, you wrote:

> Marcus Boerger wrote:
> > […]

> The executor doesn't complain about unset variables prior to calling 
> functions by reference, so I was thinking it could be modified to also 
> not complain when calling functions that don't care about set 
> variables.  Naturally, the unset variable would evaluate as `NULL` and be 
> passed as such, just there would be no E_NOTICE.

> > […]

> How do you mean?  Got any pointers?

Sorry no. Maybe Sara captures that in her book. Only places i could
imagine to touch what you need is Saras pecl/run-kit.

Best regards,
 Marcus

---

## #23290 — Antony Dovgal — 2006-05-11T23:23:47+00:00

URL: https://externals.io/message/23285#23290 · In reply to: #23288

> Antony Dovgal wrote:
> > […]
> I don't think it is.  The variable did not exist before the function was 
> called and should STILL not exist afterwards.  I believe when you pass 
> by reference, the variable will exist after the call. 

Only if you created it during the call.

<?php
function foo(&$arg) {
}

foo($nonex);
var_dump(isset($nonex));
?>

bool(false)

>  This is bad since 
> future calls to 'isset' will suddenly start returning `TRUE` when they 
> shouldn't.

-- 
Wbr, 
Antony Dovgal

---

## #23303 — Stefan Walk — 2006-05-12T12:38:19+00:00

URL: https://externals.io/message/23285#23303 · In reply to: #23290

Antony Dovgal wrote:
> Only if you created it during the call.
> 
> <?php
> function foo(&$arg) {
> }
> 
> foo($nonex);
> var_dump(isset($nonex));
> ?>
> 
> bool(false)
> 

$ php -r 'function foo(&$foo){} function bar(){ foo($var);
var_dump(get_defined_vars());} bar();'
array(1) {
  ["var"]=>
  `NULL` 
}
