|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-07-11 19:19 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2012-07-11 19:19 UTC] nikic@php.net
[2012-07-11 19:19 UTC] nikic@php.net
[2012-07-11 20:12 UTC] matthew1471 at matthew1471 dot co dot uk
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 18:00:01 2025 UTC |
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.