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

From: Date: Tue, 08 Aug 2017 20:42:23 +0000
Subject: Bug #75052 [Opn]: DateTime::__construct first argument null
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210561@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 User updated by: tim_siebels_aurich at yahoo dot de Reported by: tim_siebels_aurich at yahoo dot de Summary: DateTime::__construct first argument null Status: Open Type: Bug Package: Date/time related PHP Version: 7.2.0beta2 Block user comment: N Private report: N New Comment: I am happy with either of those. I think having null as a parameter is unnecessary, as 'now' does exactly the same. Previous Comments: ------------------------------------------------------------------------ [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.bugs (#210561) next »