You are here: Re: return a reference but it is a number, like 100 « PHP Programming Language « IT news, forums, messages
Re: return a reference but it is a number, like 100

Posted by Michael Fesser on 10/02/07 01:24

..oO(Summercool)

>the following code will let foo() return a reference something, but
>the thing being returned is a number. I thought there is no "alias"
>to a number, only to a variable?

Correct. Your code throws a notice "Only variable references should be
returned by reference [...]" since PHP 4.4.0 and 5.1.0.

>Is returning of a reference mainly
>for returning a big array or for returning an object in PHP4?

From the manual:

| Do not use return-by-reference to increase performance, the engine is
| smart enough to optimize this on its own. Only return references when
| you have a valid technical reason to do it!

> function &foo(&$i) {
> $i = 10;
> return 100;
> }
>
> $j = 1;
> print_r("$j\n");
>
> $k = foo($j);

If you return by reference, you have to use the '&' twice - for
returning the reference from the function and for assigning it to the
variable:

$k = &foo($j);

Micha

 

Navigation:

[Reply to this 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

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