Skip to content

Commit ac98ac7

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Don't assert when comparing uninit DateTimeZone objects
2 parents e083cfa + 5ae657b commit ac98ac7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ext/date/php_date.c

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

1885-
ZEND_ASSERT(o1->initialized && o2->initialized);
1885+
if (!o1->initialized || !o2->initialized) {
1886+
zend_throw_error(NULL, "Trying to compare uninitialized DateTimeZone objects");
1887+
return 1;
1888+
}
18861889

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

ext/date/tests/DateTimeZone_compare_basic1.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ 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+
try {
42+
var_dump($tz1 == $tz2);
43+
} catch (Error $e) {
44+
echo $e->getMessage(), "\n";
45+
}
46+
3247
?>
3348
--EXPECTF--
3449
compare +0200 with +0200
@@ -58,3 +73,4 @@ compare Europe/Amsterdam with Europe/Berlin
5873

5974
Warning: main(): Trying to compare different kinds of DateTimeZone objects in %s on line %d
6075
bool(false)
76+
Trying to compare uninitialized DateTimeZone objects

0 commit comments

Comments
 (0)