php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74940 DateTimeZone loose comparison always true until properties are initialized.
Submitted: 2017-07-17 12:52 UTC Modified: 2017-08-13 14:43 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: arjen at parse dot nl Assigned: jhdxr (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0 OS: irrelevant
Private report: No CVE-ID: None
 [2017-07-17 12:52 UTC] arjen at parse dot nl
Description:
------------
When using the loose equal comparision, the result is always true when the internal DateTimeZone properties have not been initialized yet.

Properties have to be 'initialized' by var_dump'ing the objects.

See https://3v4l.org/EQ1AG#v720alpha3

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

$tz = new DateTimeZone('Europe/Amsterdam');
$utc = new DateTimeZone('UTC');

var_dump($tz == $utc);

var_dump($tz === $utc);

var_dump($tz, $utc);

var_dump($tz == $utc);
var_dump($tz === $utc);

Expected result:
----------------
bool(false)
bool(false)
object(DateTimeZone)#1 (2) {
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(DateTimeZone)#2 (2) {
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
bool(false)
bool(false)

Actual result:
--------------
bool(true)
bool(false)
object(DateTimeZone)#1 (2) {
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(DateTimeZone)#2 (2) {
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
bool(false)
bool(false)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-22 05:53 UTC] heiglandreas@php.net
That seems to be related to the issue with setting internal variables on var_Dump. But from my POV it should definitely evaluate to false in ALL cases when the timezones mismatch.
 [2017-08-13 14:43 UTC] jhdxr@php.net
-Status: Open +Status: Assigned -Operating System: Linux +Operating System: irrelevant -PHP Version: 7.1.7 +PHP Version: 7.0 -Assigned To: +Assigned To: jhdxr
 [2017-08-13 14:43 UTC] jhdxr@php.net
`var_dump` will call `get_properties`, which updates properties inside the object.
 [2020-03-02 13:36 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #74940: DateTimeZone loose comparison always true
On GitHub:  https://github.com/php/php-src/pull/5227
Patch:      https://github.com/php/php-src/pull/5227.patch
 [2020-03-30 07:18 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a2f8c78183a5911bc5a923956ff531b6d27cff2a
Log: Fix #74940: DateTimeZone loose comparison always true
 [2020-03-30 07:18 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 23:01:26 2024 UTC