|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54655 unable to compare timezones instance with == operator
Submitted: 2011-05-04 11:26 UTC Modified: 2017-01-12 20:02 UTC
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:3 (37.5%)
Same OS:3 (37.5%)
From: giorgio dot liscio at email dot it Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.6 OS: any?
Private report: No CVE-ID: None
 [2011-05-04 11:26 UTC] giorgio dot liscio at email dot it
just a cosmetic problem

$a = new \DateTimeZone("Europe/Rome");
$b = new \DateTimeZone("Europe/Athens");
var_dump($a == $b); // true... not so nice
var_dump($a->getName() == $b->getName()); // false, good

all other classes of datetime lib can be compared using various operators, but not datetimezone

would be nice having this working too, if possible:

var_dump($a >= $b);
var_dump($a <= $b);

thank you


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-30 21:36 UTC] kavi at postpro dot net
 [2013-04-11 06:54 UTC] info at giorgiosironi dot com
I confirm this on PHP 5.4:
[08:45:57][giorgio@Galen:~]$ php -r "var_dump(new DateTimeZone('Europe/Rome') == 
new DateTimeZone('America/New_York'));"
[08:46:12][giorgio@Galen:~]$ php -v
PHP 5.4.9-4~oneiric+1 (cli) (built: Nov 30 2012 10:46:16) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
 [2017-01-12 20:02 UTC]
-Status: Open +Status: Not a bug
 [2017-01-12 20:02 UTC]
Comparing two classes with "==" checks whether both are instances of t he same classes.  If you want to compare also whether they are the same you have to use "===" to do so.

Have a look at

Regarding the comparison <= or >= the main question arising is: What makes one timezone higher or lower than the other one? You can not rank timezones.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jul 05 07:05:46 2022 UTC