Bug #74940 [Opn->Asn]: DateTimeZone loose comparison always true until properties are initialized.

From: Date: Sun, 13 Aug 2017 14:43:19 +0000
Subject: Bug #74940 [Opn->Asn]: DateTimeZone loose comparison always true until properties are initialized.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210654@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74940&edit=1 ID: 74940 Updated by: jhdxr@php.net Reported by: arjen at parse dot nl Summary: DateTimeZone loose comparison always true until properties are initialized. -Status: Open +Status: Assigned Type: Bug Package: Date/time related -Operating System: Linux +Operating System: irrelevant -PHP Version: 7.1.7 +PHP Version: 7.0 -Assigned To: +Assigned To: jhdxr Block user comment: N Private report: N New Comment: var_dump will call get_properties, which updates properties inside the object. Previous Comments: ------------------------------------------------------------------------ [2017-07-22 05:53:01] 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-07-17 12:52:17] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74940&edit=1

« previous php.bugs (#210654) next »