Bug #75052 [Opn->Csd]: DateTime::__construct first argument null

From: Date: Wed, 09 Aug 2017 10:41:46 +0000
Subject: Bug #75052 [Opn->Csd]: DateTime::__construct first argument null
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14886@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75052&edit=1 ID: 75052 Updated by: derick@php.net Reported by: tim_siebels_aurich at yahoo dot de Summary: DateTime::__construct first argument null -Status: Open +Status: Closed Type: Bug -Package: Date/time related +Package: Documentation problem PHP Version: 7.2.0beta2 -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: I agree, this should be a docs change. I have done that. Previous Comments: ------------------------------------------------------------------------ [2017-08-08 20:42:22] tim_siebels_aurich at yahoo dot de I am happy with either of those. I think having null as a parameter is unnecessary, as 'now' does exactly the same. ------------------------------------------------------------------------ [2017-08-08 20:34:19] danack@php.net The fix here should be in the documentation; it should be just s/null/'now'/ I think. You can also omit all parameters, if you don't need to specify the timezone. ------------------------------------------------------------------------ [2017-08-08 18:24:59] tim_siebels_aurich at yahoo dot de Description: ------------ The documentation for the DateTime constructor says that when using the $timezone parameter, the first parameter may be null [1]. Enabling strict types, an exception is thrown [2]. [1] http://php.net/manual/en/datetime.construct.php#refsect1-datetime.construct-parameters [2] https://3v4l.org/DKdFT Test script: --------------- <?php declare(strict_types=1); var_dump((new DateTime(null, new DateTimeZone('Europe/Berlin')))->format('d-m-Y H:i')); Expected result: ---------------- Current time Actual result: -------------- Fatal error: Uncaught TypeError: DateTime::__construct() expects parameter 1 to be string, null given in line 3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75052&edit=1

« previous php.doc.bugs (#14886) next »