extension can not receive unset values without E_NOTICE or reference creation

php.internals

D. Dante Lorenso

20 years ago
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

Pierre Joye

20 years ago
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

D. Dante Lorenso

20 years ago
Pierre wrote:
> On Fri, 26 May 2006 15:45:19 -0500 > dante@vocalspace.com ("D. Dante Lorenso") wrote: >> 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. >
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

Pierre Joye

20 years ago
On 5/26/06, D. Dante Lorenso <dante@vocalspace.com> wrote:
> > It is perfectly normal and desired. > > > > Not desired.
It is by design.
> > 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.
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

Marcus Börger

20 years ago
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

Sara Golemon

20 years ago
> 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

D. Dante Lorenso

20 years ago
Sara Golemon wrote:
>> 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 >
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

Wez Furlong

20 years ago
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. On 5/26/06, D. Dante Lorenso <dante@vocalspace.com> wrote:

Robert Cummings

20 years ago
On Sun, 2006-05-28 at 17:54, Wez Furlong wrote:
> 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. | `------------------------------------------------------------'

Wez Furlong

20 years ago
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. On 5/28/06, Robert Cummings <robert@interjinn.com> wrote:

Alan Knowles

20 years ago
I think he's trying to solve the infamous issetor() in an extension... Regards Alan Wez Furlong wrote: