Skip to content

Commit 5ae657b

Browse files
committed
Don't assert when comparing uninit DateTimeZone objects
Nothing guarantees that the objects are initialized here... just check as usual.
1 parent 8daf792 commit 5ae657b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ext/date/php_date.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,10 @@ static int date_object_compare_timezone(zval *tz1, zval *tz2) /* {{{ */
23902390
o1 = Z_PHPTIMEZONE_P(tz1);
23912391
o2 = Z_PHPTIMEZONE_P(tz2);
23922392

2393-
ZEND_ASSERT(o1->initialized && o2->initialized);
2393+
if (!o1->initialized || !o2->initialized) {
2394+
php_error_docref(NULL, E_WARNING, "Trying to compare uninitialized DateTimeZone objects");
2395+
return 1;
2396+
}
23942397

23952398
if (o1->type != o2->type) {
23962399
php_error_docref(NULL, E_WARNING, "Trying to compare different kinds of DateTimeZone objects");

ext/date/tests/DateTimeZone_compare_basic1.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ function compare_timezones($timezone1, $timezone2)
2929
var_dump($tz1 > $tz2);
3030
}
3131

32+
// Test comparison of uninitialized DateTimeZone objects.
33+
class MyDateTimeZone extends DateTimeZone {
34+
function __construct() {
35+
// parent ctor not called
36+
}
37+
}
38+
39+
$tz1 = new MyDateTimeZone();
40+
$tz2 = new MyDateTimeZone();
41+
var_dump($tz1 == $tz2);
42+
3243
?>
3344
--EXPECTF--
3445
compare +0200 with +0200
@@ -58,3 +69,6 @@ compare Europe/Amsterdam with Europe/Berlin
5869

5970
Warning: main(): Trying to compare different kinds of DateTimeZone objects in %s on line %d
6071
bool(false)
72+
73+
Warning: main(): Trying to compare uninitialized DateTimeZone objects in %s on line %d
74+
bool(false)

0 commit comments

Comments
 (0)