|
Posted by Rik Wasmus on 10/28/07 19:04
On Sun, 28 Oct 2007 19:25:38 +0100, duzhidian@gmail.com =
<duzhidian@gmail.com> wrote:
> Hello:
>
> When I need a function to generate a string, I have two methods:
>
> 1.
> pass by reference:
>
> mystring =3D "";
> myfunction( mystring ); // prototype of myfunction( &anystring );
>
> OR 2.
> mystring =3D myfunction(); //which return a string
>
> According to experience of C/C++, the former one is better as of the
> efficient, how about PHP?
The PHP engine is usually smarter then you think, so efficiency wise the=
re =
will be very little difference (you can test this offcourse examining ti=
me =
& memory usage). From a logical standpoint though, it makes very little =
=
sense to create a _new_ string in an existing variable by reference. I'd=
=
say functions taking arguments by reference only make sense when they =
either alter data directly related to their 'previous' value, or store t=
he =
values in come other scope.
-- =
Rik Wasmus
[Back to original message]
|