PHP Returning References?

Na. You can't pass a reference to a function name. When passing a variable by reference, if you change it's value in your function, it's value will also be changed outside of the function.

Na. You can't pass a reference to a function name. When passing a variable by reference, if you change it's value in your function, it's value will also be changed outside of the function.

For example : function test(&$var) { $var = strtolower($var); } function second_test($var) { $var = strtolower($var); } $var = 'PHP'; second_test($var); echo $var; echo "\r\n"; test($var); echo $var; This will display : PHP php As the second_test method doesn't have the variable passed by reference, it's updated value is only updated inside the function. But the test method as the variable passed by reference. So it's value will be updated inside and outside of this function.

Dmathieu You can in fact use byref in front of a function. It's perfectly legal PHP. Although since the introduction of PHP5, it's been discouraged.

– Asaph Oct 5 '09 at 14:29 Well providing a deprecated technique isn't what I'd call a good advice ;) – Damien MATHIEU Oct 5 '09 at 14:37 1 It's not deprecated in any way. Also, its use is only discouraged in situations where an object is being returned by reference, because in PHP5 it's done by default. – Ignas R Oct 5 '09 at 17:13 It was used in PHP 4 as a hack to work around shortcomings of the engine.In PHP 5 this isn't needed.

That leaves very few (if any) legal cases for using it, but it's not deprecated per se. – troelskn Oct 5 '09 at 17:57 @all, thanks for your replies. But I still want to ask: if I am not returning a class variable, in this case just a function variable, am I right to say I shld not use this (return by reference) because its already done by the engine?

– iceangel89 Oct 6 '09 at 3:16.

I believe it's referring to byref arguments not functions. For example this: function doStuff(&$value1, &$value2) { ... } is an acceptable use of byref because the doStuff() function has to return 2 values. If it only doStuff() only needed to affect one value, it would be more elegant to have the function return it, by value, of course.

The bolded part means it's useful if you want to keep a reference to a variable, instead of the value of this variable. The example about returning references, on php. Net, explains it pretty well, IMO.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions