# extension can not receive unset values without E_NOTICE or reference creation

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

---

## #23700 — D. Dante Lorenso — 2006-05-26T20:45:19+00:00

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

All,

Back on the topic of trying to write a 'filled' function in an 
extension, I have run into trouble.  I have declared a function as follows:

---------- 8< -------------------- 8< ----------
static
        ZEND_BEGIN_ARG_INFO(all_args_prefer_ref, ZEND_SEND_PREFER_REF)
        ZEND_END_ARG_INFO()

zend_function_entry shorthand_functions[] = {
        PHP_FE(filled, all_args_prefer_ref)
        {NULL, NULL, NULL}      /* Must be the last line in 
shorthand_functions[] */
};

PHP_FUNCTION(filled)
{
    RETURN_TRUE;
}
---------- 8< -------------------- 8< ----------

Then, in PHP I try the following test code:

---------- 8< -------------------- 8< ----------
<?php
$x = array();
$x["dog"] = "spot";
$x["cat"] = "moriss";
print_r($x);

// testing
print filled("testing", $x["pig"], $y->testing);
print "\n";

print_r($x);
print_r($y);
?>
---------- 8< -------------------- 8< ----------

Unfortunately, $x now contains a 'pig' key and the non-existent $y has 
been transformed into an object:

---------- 8< -------------------- 8< ----------
Array
(

    [dog] => spot
    [cat] => moriss
)
1
Array
(
    [dog] => spot
    [cat] => moriss
    [pig] => 
)
stdClass Object
(
    [testing] => 
)

---------- 8< -------------------- 8< ----------

Is there a way to define the parameters which an extension's function 
will accept to be optionally set?  The prefer-by-ref I am using is 
making the var exist even when I don't want it to.

Dante

---

## #23701 — Pierre — 2006-05-26T20:59:48+00:00

URL: https://externals.io/message/23700#23701 · In reply to: #23700

On Fri, 26 May 2006 15:45:19 -0500
dante@vocalspace.com ("D. Dante Lorenso") wrote:

> All,
> 
> Back on the topic of trying to write a 'filled' function in an 
> extension, I have run into trouble.  I have declared a function as
> follows:

It is perfectly normal and desired.

The variable is fetched before entering your function. This fetch
operation raises a E_NOTICE, create/initialize the ZVAL and pass it to
your function.

-- Pierre

---

## #23703 — D. Dante Lorenso — 2006-05-26T21:14:56+00:00

URL: https://externals.io/message/23700#23703 · In reply to: #23701

Pierre wrote:
> On Fri, 26 May 2006 15:45:19 -0500
> dante@vocalspace.com ("D. Dante Lorenso") wrote:
> > […]
> It is perfectly normal and desired.
>   

Not desired.

> The variable is fetched before entering your function. This fetch
> operation raises a E_NOTICE, create/initialize the ZVAL and pass it to
> your function.
>   

You miss the point.  If the ZVAL was created and initialized already, 
then I wouldn't be performing this exercise.  It is because the ZVAL has 
not been created that I am writing this extension.

Dante

---

## #23702 — Pierre — 2006-05-26T21:20:16+00:00

URL: https://externals.io/message/23700#23702 · In reply to: #23703

> > […]
>
> Not desired.

It is by design.

> > […]
>
> You miss the point.  If the ZVAL was created and initialized already,
> then I wouldn't be performing this exercise.  It is because the ZVAL has
> not been created that I am writing this extension.

I have no idea about what exercise you are talking about, but my
explanation is correct. If you do not understand it, please let me
know which part you don't get.

--Pierre

---

## #23705 — Marcus Boerger — 2006-05-26T22:13:09+00:00

URL: https://externals.io/message/23700#23705 · In reply to: #23700

Hello D.,

  you are looking for ZEND_BEGIN_ARG_INFO_EX(), the names of the macro
parameters are self speaking.

best regards
marcus

Friday, May 26, 2006, 10:45:19 PM, you wrote:

> All,

> Back on the topic of trying to write a 'filled' function in an 
> extension, I have run into trouble.  I have declared a function as follows:

> ---------- 8< -------------------- 8< ----------
> static
>         ZEND_BEGIN_ARG_INFO(all_args_prefer_ref, ZEND_SEND_PREFER_REF)
>         ZEND_END_ARG_INFO()

> zend_function_entry shorthand_functions[] = {
>         PHP_FE(filled, all_args_prefer_ref)
>         {NULL, NULL, NULL}      /* Must be the last line in 
> shorthand_functions[] */
> };

> PHP_FUNCTION(filled)
> {
>     RETURN_TRUE;
> }
> ---------- 8< -------------------- 8< ----------

> Then, in PHP I try the following test code:

> ---------- 8< -------------------- 8< ----------
> <?php
> $x = array();
> $x["dog"] = "spot";
> $x["cat"] = "moriss";
> print_r($x);

> // testing
> print filled("testing", $x["pig"], $y->testing);
> print "\n";

> print_r($x);
> print_r($y);
?>>
> ---------- 8< -------------------- 8< ----------

> Unfortunately, $x now contains a 'pig' key and the non-existent $y has 
> been transformed into an object:

> ---------- 8< -------------------- 8< ----------
> Array
> (

>     [dog] => spot
>     [cat] => moriss
> )
> 1
> Array
> (
>     [dog] => spot
>     [cat] => moriss
>     [pig] => 
> )
> stdClass Object
> (
>     [testing] => 
> )

> ---------- 8< -------------------- 8< ----------

> Is there a way to define the parameters which an extension's function 
> will accept to be optionally set?  The prefer-by-ref I am using is 
> making the var exist even when I don't want it to.

> Dante




Best regards,
 Marcus

---

## #23708 — Sara Golemon — 2006-05-26T23:14:38+00:00

URL: https://externals.io/message/23700#23708 · In reply to: #23700

> Back on the topic of trying to write a 'filled' function in an
> extension, I have run into trouble.  I have declared a function as
follows:
>
> Unfortunately, $x now contains a 'pig' key and the non-existent $y has
> been transformed into an object:
>
Short answer: No. What you're trying to do can not be done from an
extension.

-Sara

---

## #23709 — D. Dante Lorenso — 2006-05-26T23:32:39+00:00

URL: https://externals.io/message/23700#23709 · In reply to: #23708

Sara Golemon wrote:
> > […]
> Short answer: No. What you're trying to do can not be done from an
> extension. -Sara
>   

Can I have this feature added to the TODO list for 5.2 or 6.0?

Simple behavior definition: any ZVAL which does not exist for an 
extension's function (which doesn't care about the ZVAL's existence) 
should pass a newly created `NULL` ZVAL to the extension in place of the 
non-existent ZVAL and the non-existent ZVAL will continue to not exist 
after the function returns.

Dante

---

## #23759 — Wez Furlong — 2006-05-28T21:54:53+00:00

URL: https://externals.io/message/23700#23759 · In reply to: #23709

The `E_NOTICE` highlights a possible programmer error.
If you don't want to see it, turn off `E_NOTICE` level in your error
reporting settings.

--Wez.


> Sara Golemon wrote:
> > […]
>
> Can I have this feature added to the TODO list for 5.2 or 6.0?
>
> Simple behavior definition: any ZVAL which does not exist for an
> extension's function (which doesn't care about the ZVAL's existence)
> should pass a newly created `NULL` ZVAL to the extension in place of the
> non-existent ZVAL and the non-existent ZVAL will continue to not exist
> after the function returns.
>
> Dante

---

## #23760 — Robert Cummings — 2006-05-28T22:39:05+00:00

URL: https://externals.io/message/23700#23760 · In reply to: #23759

> The `E_NOTICE` highlights a possible programmer error.
> If you don't want to see it, turn off `E_NOTICE` level in your error
> reporting settings.

But he's specifically working on something to allow the developer to
eliminate the warnings because the developer has thought about the use
first. In short he's attempting to create a more succinct structure that
will increase code clarity but is coming up against an extension
limitation.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

---

## #23761 — Wez Furlong — 2006-05-28T22:43:04+00:00

URL: https://externals.io/message/23700#23761 · In reply to: #23760

Any uninitialized variable is a potential programmer error.
Again, if you don't want the notices, turn them off.
If you want "safe" code, turn them on and respect them.

--Wez.


> 
> > […]
>
> But he's specifically working on something to allow the developer to
> eliminate the warnings because the developer has thought about the use
> first. In short he's attempting to create a more succinct structure that
> will increase code clarity but is coming up against an extension
> limitation.
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting  |
> | a powerful, scalable system for accessing system services  |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for       |
> | creating re-usable components quickly and easily.          |
> `------------------------------------------------------------'

---

## #23762 — Alan Knowles — 2006-05-28T23:36:13+00:00

URL: https://externals.io/message/23700#23762 · In reply to: #23761

I think he's trying to solve the infamous issetor() in an extension...

Regards
Alan

Wez Furlong wrote:

> Any uninitialized variable is a potential programmer error.
> Again, if you don't want the notices, turn them off.
> If you want "safe" code, turn them on and respect them.
>
> --Wez.
>
> 
>
> > […]
