Re: [PHP4BETA] Re: convert_to_string_ex is not the solution.

From: Date: Fri, 17 Sep 1999 13:20:21 +0000
Subject: Re: [PHP4BETA] Re: convert_to_string_ex is not the solution.
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-4574@lists.php.net to get a copy of this message
zeev, i think i do agree (mostly;-) but how can i write a internal function that does not change the supplied parameters? if the scripter passes parameters via reference i should have a way to eg find out the string value for it without converting the users variable into a string! > As it should. It's consistent with the PHP 3.0 behavior (and PHP 4.0 > behavior too) - if a variable is passed by reference, any modifications > you make to it should be reflected in the outside world. If you don't > want the function to affect your variables, don't pass them by reference. i think we should have a way to write internal functions non-destructive (i don't want to modify the variable!), even if the user uses call-by-reference. that's all i'm asking for. > .... With PHP 4.0, the performance increase from passing by > reference is gone (since passing any type of argument is only a matter of > increasing reference count), but everything else still applies. as of now the performance increase is still there unless the internal function uses getParametersEx(). tc On Fri, 17 Sep 1999, Zeev Suraski wrote: > On Fri, 17 Sep 1999, Thies C. Arntzen wrote: > > > zeev, > > > > script: > > <? > > $what = 1; > > var_dump($what); > > echo strlen(&$what)."\n"; > > var_dump($what); > > ?> > > > > outputs: > > Content-Type: text/html > > > > int(1) > > 1 > > string(1) "1" > > > > so strlen still does convert it's arg into a string if if the arg is > > passed by refernce. > > As it should. It's consistent with the PHP 3.0 behavior (and PHP 4.0 > behavior too) - if a variable is passed by reference, any modifications > you make to it should be reflected in the outside world. If you don't > want the function to affect your variables, don't pass them by reference. > > If you want a plane of reference, internal functions should behave like > user functions as far as this is concerned. Consider the following > function: > > function ord_next($n) > { > return ++$n; > } > > Ok, a dumb function, but illustrative nonetheless. It's obvious that this > function would behave differently if you pass the argument by reference or > not. Same goes for internal functions. > > Note that this has nothing to do with getParametersEx(). As I mentioned, > there's full consistency with the way PHP 3.0 and 4.0 behave. Keep > strlen() as it was, and try the following code (even on PHP 3.0): > > $n = 5; > strlen(&$n); > print gettype($n); > > You would get 'string'. This is exactly the reason that we added the > 'allow pass by reference' flag in PHP 3.0, which would have better named > as 'allow implicit pass by reference', since nothing ever stops the user > from passing stuff by reference (that flag only tells PHP 3.0 if it may > pass stuff by reference even if the user didn't explicitly ask for that, > for performance reasons). As we said over a year ago, you're allowed to > use this flag only if your function uses the argument in a 'read-only' > mode, as in, doesn't modify them in ANY way, including type conversion. > You can understand from that that if the user passes arguments > by reference (explicitly) to a function that modifies its arguments, it > would modify them. With PHP 4.0, the performance increase from passing by > reference is gone (since passing any type of argument is only a matter of > increasing reference count), but everything else still applies. > > We might want to add an argument type flag that prevents passing by > reference, but I'm not sure it's required. > > Zeev > > -- > ----------------------------------------------------- > Zeev Suraski <zeev@zend.com> http://www.zend.com/ > For a PGP public key, finger bourbon@netvision.net.il > > > > -- > PHP 4 Beta > > 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

« previous php.version4 (#4574) next »