note 107115 added to datetime.sub

From: Date: Sun, 08 Jan 2012 21:19:53 +0000
Subject: note 107115 added to datetime.sub
Groups: php.notes 
Request: Send a blank email to php-notes+get-185461@lists.php.net to get a copy of this message
Follow up on php at keith tyler dot com: ANY method executed after ->sub() will continue to affect the original date object. Also, due to how object references work, modifying the resulting object of ->sub() will affect the original object. <?php $date = new DateTime(); $d = $date->sub(new DateInterval('P1Y')); $d->getTimestamp(); $d === $date; ?> The use of CLONE on the return of ->sub() avoids this. ---- Server IP: 66.207.199.35 Probable Submitter: 70.72.76.233 ---- Manual Page -- http://www.php.net/manual/en/datetime.sub.php Edit -- https://master.php.net/note/edit/107115 Del: integrated -- https://master.php.net/note/delete/107115/integrated Del: useless -- https://master.php.net/note/delete/107115/useless Del: bad code -- https://master.php.net/note/delete/107115/bad+code Del: spam -- https://master.php.net/note/delete/107115/spam Del: non-english -- https://master.php.net/note/delete/107115/non-english Del: in docs -- https://master.php.net/note/delete/107115/in+docs Del: other reasons-- https://master.php.net/note/delete/107115 Reject -- https://master.php.net/note/reject/107115 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185461) next »