Re: return a reference but it is a number, like 100
- From: Michael Fesser <netizen@xxxxxx>
- Date: Tue, 02 Oct 2007 03:24:16 +0200
..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
.
- References:
- return a reference but it is a number, like 100
- From: Summercool
- return a reference but it is a number, like 100
- Prev by Date: return a reference but it is a number, like 100
- Next by Date: Re: Proposal for Lite Encryption for Login Form without SSL
- Previous by thread: return a reference but it is a number, like 100
- Index(es):
Relevant Pages
|