Skip to content

Commit 30277a4

Browse files
committed
Fixed exception class for 'Invalid serialization data for DateTimeZone object'
1 parent 821169a commit 30277a4

8 files changed

+22
-26
lines changed

ext/date/php_date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3857,7 +3857,7 @@ PHP_METHOD(DateTimeZone, __set_state)
38573857
php_date_instantiate(date_ce_timezone, return_value);
38583858
tzobj = Z_PHPTIMEZONE_P(return_value);
38593859
if (!php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht)) {
3860-
zend_throw_error(date_ce_date_error, "Invalid serialization data for DateTimeZone object");
3860+
zend_throw_error(NULL, "Invalid serialization data for DateTimeZone object");
38613861
}
38623862
}
38633863
/* }}} */

ext/date/tests/DatePeriod_wrong_arguments.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DatePeriod invalid serialization data
2+
DatePeriod arguments/wrong arguments
33
--FILE--
44
<?php
55
$dp = new DatePeriod(new \DateTimeImmutable("2023-01-13 12:29:30"), DateInterval::createFromDateString("tomorrow"), 4);

ext/date/tests/DateTimeZone_compare_basic1.phpt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ foreach ($timezones as [$timezone1, $timezone2]) {
1414
compare_timezones($timezone1, $timezone2);
1515
}
1616

17-
var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET'));
17+
try {
18+
var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET'));
19+
} catch (DateException $e) {
20+
echo $e::class, ': ', $e->getMessage(), "\n";
21+
}
1822

1923
function compare_timezones($timezone1, $timezone2)
2024
{
@@ -70,8 +74,5 @@ compare Europe/Amsterdam with Europe/Berlin
7074
< bool(false)
7175
= bool(false)
7276
> bool(false)
73-
74-
Fatal error: Uncaught DateException: Cannot compare two different kinds of DateTimeZone objects in %s
75-
Stack trace:
76-
#0 {main}
77-
thrown in %s
77+
DateException: Cannot compare two different kinds of DateTimeZone objects
78+
Trying to compare uninitialized DateTimeZone objects

ext/date/tests/DateTimeZone_serialize_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ try {
1010
echo $e->getMessage(), "\n";
1111
}
1212
?>
13-
--EXPECTF--
13+
--EXPECT--
1414
Invalid serialization data for DateTimeZone object

ext/date/tests/DateTime_modify_invalid_format.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
DateTime::modify() with invalid format
2+
DateTime::modify() with empty string as format
33
--FILE--
44
<?php
55

ext/date/tests/bug78139.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ foreach ($strings as $string)
2121
try {
2222
$tz = new \DateTimeZone($string);
2323
} catch (DateInvalidTimeZoneException $e) {
24-
echo $e->getMessage(), "\n";
24+
echo $e::class, ': ', $e->getMessage(), "\n";
2525
}
2626

2727
echo "\n\n";
@@ -41,33 +41,33 @@ Parsing 'x UTC':
4141

4242
Warning: timezone_open(): Unknown or bad timezone (x UTC) in %sbug78139.php on line %d
4343
bool(false)
44-
DateTimeZone::__construct(): Unknown or bad timezone (x UTC)
44+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (x UTC)
4545

4646

4747
Parsing 'xx UTC':
4848

4949
Warning: timezone_open(): Unknown or bad timezone (xx UTC) in %sbug78139.php on line %d
5050
bool(false)
51-
DateTimeZone::__construct(): Unknown or bad timezone (xx UTC)
51+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (xx UTC)
5252

5353

5454
Parsing 'xUTC':
5555

5656
Warning: timezone_open(): Unknown or bad timezone (xUTC) in %sbug78139.php on line %d
5757
bool(false)
58-
DateTimeZone::__construct(): Unknown or bad timezone (xUTC)
58+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (xUTC)
5959

6060

6161
Parsing 'UTCx':
6262

6363
Warning: timezone_open(): Unknown or bad timezone (UTCx) in %sbug78139.php on line %d
6464
bool(false)
65-
DateTimeZone::__construct(): Unknown or bad timezone (UTCx)
65+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (UTCx)
6666

6767

6868
Parsing 'UTC xx':
6969

7070
Warning: timezone_open(): Unknown or bad timezone (UTC xx) in %sbug78139.php on line %d
7171
bool(false)
72-
DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)
72+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)
7373

ext/date/tests/date_interval_create_from_date_string_nullparam.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ Test date_interval_create_from_date_string() function : null parameter
44
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
55
--FILE--
66
<?php
7-
try {
8-
$i = date_interval_create_from_date_string(null);
9-
} catch (DateMalformedIntervalStringException $e) {
10-
echo $e->getMessage(), "\n";
11-
}
7+
$i = date_interval_create_from_date_string(null);
128
var_dump($i);
139
?>
1410
--EXPECTF--

ext/date/tests/date_interval_non_relative_warning.phpt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ foreach ($formats as $format) {
1717
}
1818
}
1919

20+
echo "====\n";
21+
2022
foreach ($formats as $format) {
21-
try {
22-
$d = date_interval_create_from_date_string($format);
23-
} catch (DateMalformedIntervalStringException $e) {
24-
echo $e->getMessage(), "\n";
25-
}
23+
$d = date_interval_create_from_date_string($format);
2624
}
2725

2826
?>
@@ -31,6 +29,7 @@ String 'next weekday 15:30' contains non-relative elements
3129
String '+5 hours noon' contains non-relative elements
3230
String '-8 days March 23' contains non-relative elements
3331
String '+72 seconds UTC' contains non-relative elements
32+
====
3433

3534
Warning: date_interval_create_from_date_string(): String 'next weekday 15:30' contains non-relative elements in %s on line %d
3635

0 commit comments

Comments
 (0)