Re: [PHP4BETA] new/fast API breaks passing array elements by value!
| From: | Thies C. Arntzen | Date: | Mon, 27 Sep 1999 18:21:21 +0000 |
| Subject: | Re: [PHP4BETA] new/fast API breaks passing array elements by value! | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-4969@lists.php.net to get a copy of this message | ||
On Mon, 27 Sep 1999, Andi Gutmans wrote:
> This is not a bug in the new API.
> I think you didn't quite understand how it works.
i'm pretty sure i did - you probably remember my "argue" with zeev some
days ago regarding exactly this issue.
but i have to admin that i hit sent *before* thinking this time (happened
to me before;-)
you're absolutley right, it's not a bug in the new API - and it hasn't got
anything to do with array-elements as well.
the problem is that we need to be very, very (!!) cautious when converting
to getParametersEx - the "real" but is in the new strtoupper routine!
question is, do we have a standard/simple API-call to duplicate a zval?
>
> You can only use the new API on values which you won't change in place.
> What happened in the old API is that for every argument passed by value it
> created a new zval and then let the programmer do whatever he wanted
> without it effecting the outer world. Now the approach is, if we want to
> look at a value, and it's already in the format we want, why create a copy
> of it.
> For example, if you pass a string to strlen(), convert_to_string_ex() won't
> create a new zval copy because it can read the relevant information without
> having to change the original zval. If you pass an integer to strlen() then
> convert_to_string_ex() "knows" it has to change the data, so it creates a
> copy so that the conversion wouldn't screw up anything.
that's only true for parameters *not* passed by reference.
> So the bug is in strtoupper. After calling convert_to_string_ex() it should
> copy the zval to the return_value, call zval_ctor() on the return_value,
> and then do strtoupper() on the return_value. You'd still be saving using
> the new API by not creating two copies, once for the argument gotten from
> getParameters() and once for the return_value, but just once, for the
> return_value.
ok so we should write:
getParametersEx(1,&arg);
convert_to_string_ex(arg);
return_value = arg;
zval_ctor(return_value);
## use return->value.str.val from here on...
maybe we could simplify that a bit?
tc
>
> I hope this clarifies things.
>
> Andi
>
> At 10:56 AM 9/27/99 +0200, Thies C. Arntzen wrote:
> ><?
> >$arr = array("lower");
> >echo $arr[0]."\n";
> >echo strtoupper($arr[0])."\n"; // this line *CHANGES* the array!
> >echo $arr[0]."\n";
> >?>
>
> ---
> Andi Gutmans <andi@zend.com>
> http://www.zend.com/
>
>
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany