Edit report at https://bugs.php.net/bug.php?id=55461&edit=1
ID: 55461 Updated by: [email protected] Reported by: nico at is55 dot de Summary: date_modify() affects variables recursive?! -Status: Open +Status: Bogus Type: Bug Package: Date/time related Operating System: Win7 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: since $now is a DateTime object, you should use : $later = clone $now; to accomplish your requirement. Previous Comments: ------------------------------------------------------------------------ [2011-08-19 12:07:01] nico at is55 dot de Description: ------------ --- >From manual page: http://www.php.net/function.date-modify --- I'm sorry if I did do something wrong and waste your time, but I can't explain this behaviour: date_create() gets assigned to a variable >>> $now this variable ($now) is being copied to another variable ($later) and this new variable ($later) then modified with date_modify() to be 30 days in the past ODD BEHAVIOUR: after this is executed BOTH variables, $now and $later are 30 days in the past? Test script: --------------- <?php $now = date_create(); # get current datetime $later = $now; # copy $now to $later date_modify($later,'-30 day'); $now_str = date_format($now,'Y-m-d H:i:s'); $later_str = date_format($later,'Y-m-d H:i:s'); echo "\$now_str: ".$now_str."</br>"; echo "\$later_str: ".$later_str."</br>"; ?> /* $now_str: 2011-07-20 22:05:31 $later_str: 2011-07-20 22:05:31 */ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55461&edit=1
