From:             matthew1471 at matthew1471 dot co dot uk
Operating system: Windows Server 2003 SP2
PHP version:      5.3.14
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Changes To A Copied DateTime Variable Always Changes Original

Description:
------------
Interacting with a copied DateTime variable (without using the reference
'&' syntax) still changes the original variable.

Test script:
---------------
<?php
// Get today's date.
$originalDate = date_create();;

// Take a copy.
$copiedDate = $originalDate;
// This *will* work for some reason : $copiedDate = clone $originalDate;

echo 'originalDate=' . date_format($originalDate, 'Y-m-d') . '<br/>';

// Add 1 day.
date_add($copiedDate, date_interval_create_from_date_string('1 days'));
// This doesn't work either :
$copiedDate->add(date_interval_create_from_date_string('1 days'));

// $originalDate *SHOULD* still be the same.
echo 'originalDate=' . date_format($originalDate, 'Y-m-d') . '<br/>';

// This behaviour if desired is different with other objects:
$originalString = array('Sausages');
echo $originalString[0] . '<br/>';
$copiedString = $originalString;
$copiedString[0] = 'Ice Cream';
echo $originalString[0] . '<br/>';
?>

Expected result:
----------------
The $originalDate to remain the same as it was before $copiedDate was
changed.

Actual result:
--------------
$originalDate changes.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62532&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62532&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62532&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62532&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62532&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62532&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62532&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62532&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62532&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62532&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62532&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62532&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62532&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62532&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62532&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62532&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62532&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62532&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62532&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62532&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62532&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62532&r=mysqlcfg

Reply via email to