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

From: Date: Mon, 27 Sep 1999 17:41:38 +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-4965@lists.php.net to get a copy of this message
This is not a bug in the new API. I think you didn't quite understand how it works. 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. 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. 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/

« previous php.version4 (#4965) next »