#23359 [NEW]: Passing by reference oddity

From: Date: Sat, 26 Apr 2003 11:06:00 +0000
Subject: #23359 [NEW]: Passing by reference oddity
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-38439@lists.php.net to get a copy of this message
From: chen at hivemail dot com Operating system: Windows XP PHP version: 4CVS-2003-04-26 (stable) PHP Bug Type: Variables related Bug description: Passing by reference oddity 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 bug report at http://bugs.php.net/?id=23359&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=23359&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=23359&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=23359&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=23359&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=23359&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=23359&r=support Expected behavior: http://bugs.php.net/fix.php?id=23359&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=23359&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=23359&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=23359&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23359&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=23359&r=dst IIS Stability: http://bugs.php.net/fix.php?id=23359&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=23359&r=gnused

« previous php.bugs (#38439) next »