|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52063 DateTime constructor's second argument doesn't have a null default value
Submitted: 2010-06-12 12:29 UTC Modified: 2011-01-24 02:15 UTC
Avg. Score:3.7 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.2 OS: Irrelevant
Private report: No CVE-ID: None
 [2010-06-12 12:29 UTC]
DateTime's constructor is documented like this:

public DateTime::__construct ([ string $time = "now" [, DateTimeZone $timezone = NULL ]] )

However, not passing the constructor the second argument is not the same as passing NULL. Fixing this is just a matter of adding a "!", like this

if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {


if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {

Test script:

$a = new DateTime("2009-01-01", null);
echo $a->format(DateTime::COOKIE);

Expected result:
Thursday, 01-Jan-09 00:00:00 WET

Actual result:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() expects parameter 2 to be DateTimeZone, null given' in /tmp/cpCZPA42:4 Stack trace: #0 /tmp/cpCZPA42(4): DateTime->__construct('2009-01-01', NULL) #1 {main} thrown in /tmp/cpCZPA42 on line 4


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-12 14:58 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2011-01-24 02:15 UTC]
Automatic comment from SVN on behalf of stas
Log: Fixed Bug #52063 (DateTime constructor's second argument doesn't have a null default value)
 [2011-01-24 02:15 UTC]
-Status: Assigned +Status: Closed
 [2011-01-24 02:15 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Sep 27 06:01:24 2023 UTC