Bug #55461 [NEW]: date_modify() affects variables recursive?!
| From: | nico at is55 dot de | Date: | Fri, 19 Aug 2011 12:07:01 +0000 |
| Subject: | Bug #55461 [NEW]: date_modify() affects variables recursive?! | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-162694@lists.php.net to get a copy of this message | ||
From:
Operating system: Win7
PHP version: Irrelevant
Package: Date/time related
Bug Type: Bug
Bug description:date_modify() affects variables recursive?!
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 bug report at https://bugs.php.net/bug.php?id=55461&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55461&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55461&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55461&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=55461&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55461&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=55461&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=55461&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=55461&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=55461&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=55461&r=support
Expected behavior: https://bugs.php.net/fix.php?id=55461&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=55461&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=55461&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=55461&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55461&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55461&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=55461&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=55461&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=55461&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=55461&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=55461&r=mysqlcfg