Re: return a reference but it is a number, like 100



..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
.



Relevant Pages

  • Re: Returning References
    ... Do not use return-by-reference to increase performance, the engine is ... No, return by reference will not increase performance even in PHP4, ... common PHP application is the Database, ...
    (comp.lang.php)
  • Re: true-random number generator (TRNG) info.
    ... was putting forth a crackpot idea? ... I guess his reference to poker wasn't much ... Uhhhh....you didn't say anything at all about his creating an alias ... You have a warped understanding of the word "logic". ...
    (rec.gambling.poker)
  • Re: OSRegSetValueEx versus RegSetValueEx
    ... I went through code and almost each function has some Alias attached to it. ... >> I cannot find any reference to it on MSDN site, ... > It's an excellent registry class that I use whenever I need registry ...
    (microsoft.public.vb.general.discussion)
  • Re: on merging datasets and datatables
    ... Your code doesn't work because you are simply creating another reference to ... an existing DataTable object; you are not actually creating a new data ... Please do not send e-mail directly to this alias. ... > into a single dataset, so as to have a single dataset with the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Switch alias names....
    ... Filtered indexes? ... and then in the INIT event 'fool' all the controls on the form into ... Use table again in 0 alias foo order 1 ... It just means I can have a 'common' form2 that can reference either ...
    (microsoft.public.fox.programmer.exchange)