php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75052 DateTime::__construct first argument null
Submitted: 2017-08-08 18:24 UTC Modified: 2017-08-09 10:41 UTC
From: tim_siebels_aurich at yahoo dot de Assigned: derick (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.2.0beta2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tim_siebels_aurich at yahoo dot de
New email:
PHP Version: OS:

 

 [2017-08-08 18:24 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-08 20:34 UTC] 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 20:42 UTC] 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-09 10:41 UTC] derick@php.net
-Status: Open +Status: Closed -Package: Date/time related +Package: Documentation problem -Assigned To: +Assigned To: derick
 [2017-08-09 10:41 UTC] derick@php.net
I agree, this should be a docs change. I have done that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 23:01:29 2024 UTC