php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42268 assignment in reference parameter doesn't resolve properly
Submitted: 2007-08-10 20:48 UTC Modified: 2007-08-13 09:46 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: donauinsel at hotmail dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.2.4RC1 OS: W32
Private report: No CVE-ID: None
 [2007-08-10 20:48 UTC] donauinsel at hotmail dot com
Description:
------------
Try first $month = 11,$year = 2007 then $month =12, $year = 2007
Function returns correct value which seems not to be passed correctly.

Reproduce code:
---------------
function fixdate(&$month, &$year) {
	if ($month < 1) {
		$month = 12;
		$year--;
	} elseif ($month > 12) {
		$month = 1;
		$year++;
	}
}

fixdate($nextmonth = ($month + 1), $nextyear = ($year + 0));



Expected result:
----------------
12 / 2007 or 01 / 2008 

Actual result:
--------------
you will get 13 / 2007 instead.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-10 21:43 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2007-08-11 04:21 UTC] donauinsel at hotmail dot com
Sorry i don't understand what you mean. I use the pass-by-reference function with global variable.
 [2007-08-11 06:33 UTC] donauinsel at hotmail dot com
This works by example also when using references. So there is going something wrong with php.

$prevmonth = ($month - 1);
$prevyear = ($year + 0);
$nextmonth = ($month + 1);
$nextyear = ($year + 0);

fixdate($prevmonth, $prevyear);
fixdate($nextmonth, $nextyear);
 [2007-08-13 09:22 UTC] donauinsel at hotmail dot com
Can you please explain why it works until latest PHP release but not in 5.2.3 ?!
 [2007-08-13 09:46 UTC] donauinsel at hotmail dot com
Sorry , missed message from Cristian Rodriguez. Thanks for explaining.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC