@ 2015-04-19T22:32:18Z <?php
// Create two identical DateTime objects
$a = new DateTime("2015-02-01 00:00:00", new DateTimeZone("PST"));
$b = clone $a;
// They should be equal (and they are)
compare($a, $b);
// Now change the timezone to EST.
$b->setTimezone(new DateTimeZone("EST"));
//The actual timestamp should not change (it does not in PHP 5.4) so $a should still be equal to $b, but it will say $a > $b.
compare($a, $b);
function compare($a, $b) {
var_dump($a);
var_dump($b);
echo ($a > $b ? '$a > $b' : ($a < $b ? '$a < $b' : ($a == $b ? '$a == $b' : 'undefined'))) . "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.17 - 7.0.33 , 7.1.3 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 03:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "EST"
}
$a == $b
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 03:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "EST"
}
$a == $b
Output for 5.5.14 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.16 , 7.1.0 - 7.1.2 object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 03:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "EST"
}
$a > $b
Output for 5.5.10 - 5.5.13 object(DateTime)#1 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "PST"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2015-02-01 03:00:00"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "EST"
}
$a > $b
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.29 , 5.5.0 - 5.5.9 object(DateTime)#1 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(19) "2015-02-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2015-02-01 03:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "America/New_York"
}
$a == $b
Output for 5.4.30 - 5.4.45 object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
$a == $b
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-02-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2015-02-01 03:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "America/New_York"
}
$a == $b
Output for 5.2.0 - 5.2.17 object(DateTime)#1 (0) {
}
object(DateTime)#2 (0) {
}
$a == $b
object(DateTime)#1 (0) {
}
object(DateTime)#2 (0) {
}
$a == $b
Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 Fatal error: Class 'DateTime' not found in /in/dTOrf on line 4
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_VARIABLE in /in/dTOrf on line 5
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_VARIABLE in /in/dTOrf on line 5
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/dTOrf on line 5
Process exited with code 255 . preferences:dark mode live preview
301.75 ms | 401 KiB | 459 Q