Reply to Re: Passing by reference better than returning a value when calling a function?

Your name:

Reply:


Posted by Michael Fesser on 10/28/07 21:39

..oO(duzhidian@gmail.com)

>When I need a function to generate a string, I have two methods:
>
>1.
>pass by reference:
>
>mystring = "";
>myfunction( mystring ); // prototype of myfunction( &anystring );
>
>OR 2.
>mystring = myfunction(); //which return a string
>
>According to experience of C/C++, the former one is better as of the
>efficient, how about PHP?

PHP is not C/C++. Don't compare C's references or pointers with
references in PHP.

If you really have a use for references, then use them. But in all other
cases just use what makes more sense in the application context. Usually
I prefer to have a function return its result, since this allows to
easily nest function calls. The code is more readable (at least for me).

Actually I think that in my own framework there's currently not a single
function that requires arguments passed by reference. Some functions use
references internally, for example for traversing through an array tree,
but in most if not all functions arguments are passed by value.

Micha

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация