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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC