我创建的基础上创建的第一个两个日期时间函数:为什么我的变量通过引用传递?
// initial datetime (for test)
$dt = new \Datetime;
$dt->setDate(2012, 9, 5);
// splitting into 2 different datetimes
$dates = $this->defineLimitsByDate($dt);
// $dates[0] = 2011-07-01
// $dates[1] = 2012-09-01
就目前而言,一切的权利。现在,我通过这些日期时间到我用一个while
循环,直到她达到第二个是递增的第一次约会的其他功能:
// now I use the 2 datetimes into a function...
$dateKeys = $this->generateDateKeys($dates[0], $dates[1]);
// and the function seems to modify them outside itself !
// $dates[0] = 2012-10-01
// $dates[1] = 2012-09-01
看来,我的函数内部while循环generateDateKeys
未在本地修改参数。它改变函数外部的$日期的值。但我从不使用引用传递。
任何人都可以启发我吗?
对象(基本上)通过引用传递。参见这里了解更多详情:http://php.net/manual/en/language.oop5.references.php – Steve 2014-10-08 12:52:06