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
Status: Assigned Package: Date/time related
PHP Version: 7.0 OS: irrelevant
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC