php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68669 DateTime::createFromFormat() does not allow NULL $timezone
Submitted: 2014-12-28 22:31 UTC Modified: 2015-06-29 03:56 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ocramius at gmail dot com Assigned: neeke (profile)
Status: Closed Package: Date/time related
PHP Version: 5.6.4 OS:
Private report: No CVE-ID: None
 [2014-12-28 22:31 UTC] ocramius at gmail dot com
Description:
------------
`DateTime::createFromFormat($format, $time, DateTimeZone $timezone = null)` has a default value for its third parameter `$timezone`, but it doesn't accept `null` as a value.

Running the following script will raise a warning:

DateTime::createFromFormat('Y/m/d', '2015/1/1', null);

// Warning: DateTime::createFromFormat() expects parameter 3 to be DateTimeZone, null given

While the documentation states that the default timezone is going to be used when no parameter is given, also the case where a `null` `$timezone` is given should be handled correctly.

This would align the API to the language semantics about default values.

Test script:
---------------
<?php

var_dump(get_class(DateTime::createFromFormat('Y/m/d', '2015/1/1', null)));

Expected result:
----------------
string(8) "DateTime"

Actual result:
--------------
Warning: DateTime::createFromFormat() expects parameter 3 to be DateTimeZone, null given in %a on line 3
Warning: get_class() expects parameter 1 to be object, boolean given in %a on line 3 bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-10 15:43 UTC] neeke@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: neeke
 [2015-04-20 07:06 UTC] christophe at gesche dot org
idem with  ubuntu  & php 5.5.9
 [2015-06-29 03:56 UTC] neeke@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 20:04:13 2023 UTC