Re: [PHP4BETA] new/fast API breaks passing array elements by value!

From: Date: Mon, 27 Sep 1999 18:56:48 +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-4970@lists.php.net to get a copy of this message
BTW, although some of you guys liked the fact that strlen(&$str) converted $str, it really is not a documented feature and we should not support it. At least not intentionally and not by adding complexity to our code. So although you could support strtoupper(&$str) easily by going back to the old getParameters() API, I would not make this the reason to fallback. We should not officially support obscure behavior of these functions and when possible we should minimize it. All in all, convert_to_*_ex is good enough for most functions, as most don't change the arguments they receive within the function. In the case of strtoupper() and friends we should either go back to the old API or do what I suggested it. Making a macro like ZVAL_COPY(return_value,arg) is not a biggy and then strtoupper would look something like. (Pseudo code) convert_to_string_ex(arg1); ZVAL_COPY(return_value,arg1); strtoupper(return_value); Andi At 08:21 PM 9/27/99 +0200, Thies C. Arntzen wrote:
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
--- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.version4 (#4970) next »