Skip to content

Commit 274ae05

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Add missing returns in ext/date for PHP 8.3+ (php#15735)
2 parents 2513258 + cb69900 commit 274ae05

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

ext/date/php_date.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static void date_throw_uninitialized_error(zend_class_entry *ce)
318318
}
319319
if (ce_ptr->type != ZEND_INTERNAL_CLASS) {
320320
zend_throw_error(date_ce_date_object_error, "Object of type %s not been correctly initialized by calling parent::__construct() in its constructor", ZSTR_VAL(ce->name));
321+
return;
321322
}
322323
zend_throw_error(date_ce_date_object_error, "Object of type %s (inheriting %s) has not been correctly initialized by calling parent::__construct() in its constructor", ZSTR_VAL(ce->name), ZSTR_VAL(ce_ptr->name));
323324
}
@@ -4093,6 +4094,7 @@ PHP_METHOD(DateTimeZone, __construct)
40934094
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &exception_message)) {
40944095
zend_throw_exception_ex(date_ce_date_invalid_timezone_exception, 0, "DateTimeZone::__construct(): %s", exception_message);
40954096
efree(exception_message);
4097+
RETURN_THROWS();
40964098
}
40974099
}
40984100
/* }}} */
@@ -4648,11 +4650,6 @@ PHP_METHOD(DateInterval, __construct)
46484650

46494651
static void php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht) /* {{{ */
46504652
{
4651-
/* If ->diff is already set, then we need to free it first */
4652-
if ((*intobj)->diff) {
4653-
timelib_rel_time_dtor((*intobj)->diff);
4654-
}
4655-
46564653
/* If we have a date_string, use that instead */
46574654
zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string"));
46584655
if (date_str && Z_TYPE_P(date_str) == IS_STRING) {
@@ -4667,6 +4664,14 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte
46674664
Z_STRVAL_P(date_str),
46684665
err->error_messages[0].position,
46694666
err->error_messages[0].character ? err->error_messages[0].character : ' ', err->error_messages[0].message);
4667+
timelib_time_dtor(time);
4668+
timelib_error_container_dtor(err);
4669+
return;
4670+
}
4671+
4672+
/* If ->diff is already set, then we need to free it first */
4673+
if ((*intobj)->diff) {
4674+
timelib_rel_time_dtor((*intobj)->diff);
46704675
}
46714676

46724677
(*intobj)->diff = timelib_rel_time_clone(&time->relative);
@@ -4681,6 +4686,11 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte
46814686
return;
46824687
}
46834688

4689+
/* If ->diff is already set, then we need to free it first */
4690+
if ((*intobj)->diff) {
4691+
timelib_rel_time_dtor((*intobj)->diff);
4692+
}
4693+
46844694
/* Set new value */
46854695
(*intobj)->diff = timelib_rel_time_ctor();
46864696

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
Test that DateInterval::__unserialize() doesn't modify state in case of a date_string format error
3+
--FILE--
4+
<?php
5+
6+
$interval = new DateInterval("P1Y1DT1H1M");
7+
8+
var_dump($interval);
9+
10+
try {
11+
$interval->__unserialize(
12+
[
13+
"date_string" => "wrong",
14+
]
15+
);
16+
} catch (Error $e) {
17+
echo $e->getMessage() . "\n";
18+
}
19+
20+
var_dump($interval);
21+
22+
?>
23+
--EXPECTF--
24+
object(DateInterval)#%d (%d) {
25+
["y"]=>
26+
int(1)
27+
["m"]=>
28+
int(0)
29+
["d"]=>
30+
int(1)
31+
["h"]=>
32+
int(1)
33+
["i"]=>
34+
int(1)
35+
["s"]=>
36+
int(0)
37+
["f"]=>
38+
float(0)
39+
["invert"]=>
40+
int(0)
41+
["days"]=>
42+
bool(false)
43+
["from_string"]=>
44+
bool(false)
45+
}
46+
Unknown or bad format (wrong) at position 0 (w) while unserializing: The timezone could not be found in the database
47+
object(DateInterval)#%d (%d) {
48+
["y"]=>
49+
int(1)
50+
["m"]=>
51+
int(0)
52+
["d"]=>
53+
int(1)
54+
["h"]=>
55+
int(1)
56+
["i"]=>
57+
int(1)
58+
["s"]=>
59+
int(0)
60+
["f"]=>
61+
float(0)
62+
["invert"]=>
63+
int(0)
64+
["days"]=>
65+
bool(false)
66+
["from_string"]=>
67+
bool(false)
68+
}

0 commit comments

Comments
 (0)