php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66323 IntlDateFormatter returns null when DateTimeZone value provided.
Submitted: 2013-12-19 08:07 UTC Modified: 2013-12-19 21:22 UTC
From: pavvka at gmail dot com Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: 5.5.7 OS: Linux
Private report: No CVE-ID: None
 [2013-12-19 08:07 UTC] pavvka at gmail dot com
Description:
------------
When creating instance of IntlDateFormatter and DateTimeZone value is provided, object is not created and null value is returned instead.

If 4th parameter (\DateTimeZone::UTC) is not provided, IntlDateFormatter object is created.

Test script:
---------------
<?php
$f1 = new \IntlDateFormatter(\Locale::getDefault(), 1, \IntlDateFormatter::NONE);
var_dump($f1);

$f2 = new \IntlDateFormatter(\Locale::getDefault(), 1, \IntlDateFormatter::NONE, \DateTimeZone::UTC);
var_dump($f2);

$f3 = new \IntlDateFormatter(\Locale::getDefault(), 1, \IntlDateFormatter::NONE, \DateTimeZone::EUROPE);
var_dump($f3);


Expected result:
----------------
class IntlDateFormatter#1 (0) {
}
class IntlDateFormatter#2 (0) {
}
class IntlDateFormatter#3 (0) {
}

Actual result:
--------------
class IntlDateFormatter#1 (0) {
}
NULL
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-19 17:35 UTC] aharvey@php.net
-Package: Date/time related +Package: intl
 [2013-12-19 21:22 UTC] mj@php.net
-Status: Open +Status: Not a bug
 [2013-12-19 21:22 UTC] mj@php.net
The fourth argument of IntlDateFormatter's constructor can either be a valid timezone identifier from the ICU database or an instance of IntlTimeZone or DateTimeZone. The constants in your example are just integers, which will not work.

What's odd is that the constructor is returning NULL. According to the documentation it should return FALSE. I'll look into that.
 [2014-07-31 11:53 UTC] fpruis at e-sites dot nl
A constructor should never return either false or null, but throw an exception when construction fails. 

Either way, this seems like broken backward compatibility. Passing an integer (from DateTimeZone::UTC) used to work with v3.6, but now we upgraded to v4.8.1.1 it is broken.

We will be upgrading Symfony (v2.0.4) to resolve the issue for us, but I do recommend having the constructor throw an exception instead of returning null.
 [2016-05-04 10:52 UTC] heah at heahprod dot com
Hi, what's the status of this issue?
 [2017-05-31 15:44 UTC] imprec at gmail dot com
Reproduced the issue, it's related to the datetimezone name parsing.

For instance, this fails:

new \IntlDateFormatter(\Locale::getDefault(), 1, \IntlDateFormatter::NONE, 'utc');

Whereas this succeeds:

new \IntlDateFormatter(\Locale::getDefault(), 1, \IntlDateFormatter::NONE, 'UTC');
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC