1--TEST--
2Test of compare object handler for DateTimeZone objects
3--FILE--
4<?php
5
6$timezones = array(
7    ['+0200', '-0200'],
8    ['EST', 'PST'],
9    ['Europe/Amsterdam', 'Europe/Berlin']
10);
11
12foreach ($timezones as [$timezone1, $timezone2]) {
13    compare_timezones($timezone1, $timezone1);
14    compare_timezones($timezone1, $timezone2);
15}
16
17try {
18	var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET'));
19} catch (DateException $e) {
20	echo $e::class, ': ', $e->getMessage(), "\n";
21}
22
23function compare_timezones($timezone1, $timezone2)
24{
25    $tz1 = new DateTimeZone($timezone1);
26    $tz2 = new DateTimeZone($timezone2);
27    echo "compare $timezone1 with $timezone2\n";
28    echo "< ";
29    var_dump($tz1 < $tz2);
30    echo "= ";
31    var_dump($tz1 == $tz2);
32    echo "> ";
33    var_dump($tz1 > $tz2);
34}
35
36// Test comparison of uninitialized DateTimeZone objects.
37class MyDateTimeZone extends DateTimeZone {
38    function __construct() {
39         // parent ctor not called
40    }
41}
42
43$tz1 = new MyDateTimeZone();
44$tz2 = new MyDateTimeZone();
45try {
46    var_dump($tz1 == $tz2);
47} catch (Error $e) {
48    echo $e::class, ': ', $e->getMessage(), "\n";
49}
50
51?>
52--EXPECTF--
53compare +0200 with +0200
54< bool(false)
55= bool(true)
56> bool(false)
57compare +0200 with -0200
58< bool(false)
59= bool(false)
60> bool(false)
61compare EST with EST
62< bool(false)
63= bool(true)
64> bool(false)
65compare EST with PST
66< bool(false)
67= bool(false)
68> bool(false)
69compare Europe/Amsterdam with Europe/Amsterdam
70< bool(false)
71= bool(true)
72> bool(false)
73compare Europe/Amsterdam with Europe/Berlin
74< bool(false)
75= bool(false)
76> bool(false)
77DateException: Cannot compare two different kinds of DateTimeZone objects
78DateObjectError: Trying to compare uninitialized DateTimeZone objects
79