|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71108 date_create() is NOT an alias for "new DateTime()"
Submitted: 2015-12-13 10:46 UTC Modified: 2017-01-28 13:02 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: public at grik dot net Assigned:
Status: Open Package: Date/time related
PHP Version: Irrelevant OS: irrelevant
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.
Block user comment
Status: Assign to:
Bug Type:
From: public at grik dot net
New email:
PHP Version: OS:


 [2015-12-13 10:46 UTC] public at grik dot net
From manual page:

date_create() is NOT an alias, It is closer to be named a factory.

For the first hand, DateTime::__construct() can't be called, which is obvious.

For another, there is a significant difference between date_create() and "new DateTime()"

We write 
if (!($DateTime = date_create('garbage'))){
//process error
try {
  $DateTime = new DateTime('garbage');
}catch(Exception $E){

Test script:
$ php -r 'var_dump(date_create("garbage"));'
$ php -r 'var_dump(new DateTime("garbage"));'

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (garbage) at position 0 (s): The timezone could not be found in the database' in Command line code:1
Stack trace:
#0 Command line code(1): DateTime->__construct('garbage')
#1 {main}
thrown in Command line code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-28 13:02 UTC]
-Package: Documentation problem +Package: Date/time related
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jul 28 18:01:25 2021 UTC