#23359 [Opn->Bgs]: Passing by reference oddity
| From: | sniper@php.net | Date: | Mon, 28 Apr 2003 14:32:57 +0000 |
| Subject: | #23359 [Opn->Bgs]: Passing by reference oddity | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-38568@lists.php.net to get a copy of this message | ||
ID: 23359
Updated by: sniper@php.net
Reported By: chen at hivemail dot com
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: Windows XP
PHP Version: 4CVS-2003-04-26 (stable)
New Comment:
Not bug:
http://www.php.net/manual/en/language.references.pass.php
Previous Comments:
------------------------------------------------------------------------
[2003-04-26 06:06:00] chen at hivemail dot com
Ok... I'll try my best to explain the problem. I have the following
function:
function fixdate(&$month, &$year) {
if ($month < 1) {
$month = 12;
$year--;
} elseif ($month > 12) {
$month = 1;
$year++;
}
}
So far so good, the function itself works ok. But when I try to do the
following:
fixdate($prevmonth = ($month - 1), $prevyear = $year);
I get this error:
Fatal error: Only variables can be passed by reference in C:\foo.php
on line 181
However, this code works as expected:
fixdate($prevmonth = ($month - 1), $prevyear = ($year + 0));
You'd expect the first code ($prevyear = $year) to work as well,
wouldn't you? The reason I use $prevyear = $year and not just pass
$year is because I need to keep the value of $year after the function
has executed.
This might be related to the way PHP copies variables, I'm not sure. If
you need any more information, let me know. :)
Thanks,
Chen
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23359&edit=1