note 99386 modified in class.datetime by davey
| From: | davey@php.net | Date: | Wed, 18 Jun 2014 04:54:29 +0000 |
| Subject: | note 99386 modified in class.datetime by davey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199709@lists.php.net to get a copy of this message | ||
please note that using
setTimezone
setTimestamp
setDate
setTime
etc..
will modify the original object, and the return value is $this
$original = new DateTime("now");
$modified = $original->setTimezone(new DateTimezone("europe/rome"));
echo $original === $modified ? "THE OBJECT IS THE SAME" : "OBJECTS ARE
DIFFERENT";
so a datetime object is mutable
(Editors note: PHP 5.5 adds DateTimeImmutable which does not modify the original object, instead
creating a new instance.)
--was--
please note that using
setTimezone
setTimestamp
setDate
setTime
etc..
will modify the original object, and the return value is $this
$original = new DateTime("now");
$modified = $original->setTimezone(new DateTimezone("europe/rome"));
echo $original === $modified ? "THE OBJECT IS THE SAME" : "OBJECTS ARE
DIFFERENT";
so a datetime object is mutable
(Editors note: PHP 5.5 adds DateTimeImmutable which does not modify the original object, instead
creating a new instance.)
http://php.net/manual/en/class.datetime.php