note 123474 added to datetimeimmutable.settimestamp
| From: | ben at hl9 dot net | Date: | Fri, 28 Dec 2018 19:21:28 +0000 |
| Subject: | note 123474 added to datetimeimmutable.settimestamp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209962@lists.php.net to get a copy of this message | ||
Note that this is not the right way to initiate a \DateTimeImmutable object with a numeric Unix
timestamp.
<?php
// Wrong, despite the documention *kind of* alluding to it
$obj = \DateTimeImmutable::setTimestamp(time() - 1);
// Also won't work
$obj = new \DateTimeImmutable(time() - 1)
// Correct, works, clean single line
$obj = (new \DateTimeImmutable())->setTimestamp(time() - 1);
?>
... In fact, this is a non-static method and thus should not be called statically.
----
Server IP: 208.43.231.9
Probable Submitter: 2a01:4a0:38:1::3 (proxied: 165.84.226.91)
----
Manual Page -- http://php.net/manual/en/datetimeimmutable.settimestamp.php
Edit -- https://master.php.net/note/edit/123474
Del: integrated -- https://master.php.net/note/delete/123474/integrated
Del: useless -- https://master.php.net/note/delete/123474/useless
Del: bad code -- https://master.php.net/note/delete/123474/bad+code
Del: spam -- https://master.php.net/note/delete/123474/spam
Del: non-english -- https://master.php.net/note/delete/123474/non-english
Del: in docs -- https://master.php.net/note/delete/123474/in+docs
Del: other reasons-- https://master.php.net/note/delete/123474
Reject -- https://master.php.net/note/reject/123474
Search -- https://master.php.net/manage/user-notes.php