note 123428 added to datetimeimmutable.add

From: Date: Wed, 12 Dec 2018 23:00:53 +0000
Subject: note 123428 added to datetimeimmutable.add
Groups: php.notes 
Request: Send a blank email to php-notes+get-209890@lists.php.net to get a copy of this message
Please note, add() works a litte different than for DateTime-Objects. Since DateTimeImmutable is in fact immutable. A line like this will not work: $di = new DateTimeImmutable("2018-12-12T10:00:00"); $di->add(new DateInterval('PT45M')); // $di unchanged !!! compared to $dt = new DateTime("2018-12-12T10:00:00"); $dt->add(new DateInterval('PT45M')); // added 45 minutes so you need to write $di = new DateTimeImmutable("2018-12-12T10:00:00"); $di = $di->add(new DateInterval('PT45M')); // $di now changed ---- Server IP: 208.43.231.9 Probable Submitter: 77.8.136.162 ---- Manual Page -- http://php.net/manual/en/datetimeimmutable.add.php Edit -- https://master.php.net/note/edit/123428 Del: integrated -- https://master.php.net/note/delete/123428/integrated Del: useless -- https://master.php.net/note/delete/123428/useless Del: bad code -- https://master.php.net/note/delete/123428/bad+code Del: spam -- https://master.php.net/note/delete/123428/spam Del: non-english -- https://master.php.net/note/delete/123428/non-english Del: in docs -- https://master.php.net/note/delete/123428/in+docs Del: other reasons-- https://master.php.net/note/delete/123428 Reject -- https://master.php.net/note/reject/123428 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209890) next »