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 17var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET')); 18 19function compare_timezones($timezone1, $timezone2) 20{ 21 $tz1 = new DateTimeZone($timezone1); 22 $tz2 = new DateTimeZone($timezone2); 23 echo "compare $timezone1 with $timezone2\n"; 24 echo "< "; 25 var_dump($tz1 < $tz2); 26 echo "= "; 27 var_dump($tz1 == $tz2); 28 echo "> "; 29 var_dump($tz1 > $tz2); 30} 31 32// Test comparison of uninitialized DateTimeZone objects. 33class MyDateTimeZone extends DateTimeZone { 34 function __construct() { 35 // parent ctor not called 36 } 37} 38 39$tz1 = new MyDateTimeZone(); 40$tz2 = new MyDateTimeZone(); 41try { 42 var_dump($tz1 == $tz2); 43} catch (Error $e) { 44 echo $e->getMessage(), "\n"; 45} 46 47?> 48--EXPECTF-- 49compare +0200 with +0200 50< bool(false) 51= bool(true) 52> bool(false) 53compare +0200 with -0200 54< bool(false) 55= bool(false) 56> bool(false) 57compare EST with EST 58< bool(false) 59= bool(true) 60> bool(false) 61compare EST with PST 62< bool(false) 63= bool(false) 64> bool(false) 65compare Europe/Amsterdam with Europe/Amsterdam 66< bool(false) 67= bool(true) 68> bool(false) 69compare Europe/Amsterdam with Europe/Berlin 70< bool(false) 71= bool(false) 72> bool(false) 73 74Warning: main(): Trying to compare different kinds of DateTimeZone objects in %s on line %d 75bool(false) 76Trying to compare uninitialized DateTimeZone objects 77