Skip to content

Commit 96c2522

Browse files
committed
add exception catch, dtor pointers and fix CI
1 parent b16f89e commit 96c2522

6 files changed

Lines changed: 17 additions & 15 deletions

File tree

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ PHP NEWS
6262
. Fixed bug GH-20426 (Spoofchecker::setRestrictionLevel() error message
6363
suggests missing constants). (DanielEScherzer)
6464
. Added grapheme_strrev (Yuya Hamada)
65-
. IntlDateFormatter::formatObject() now accepts numeric-castable objects as
65+
. IntlDateFormatter::format() now accepts numeric-castable objects as
6666
date/time values. (Weilin Du)
6767

6868
- JSON:

UPGRADING

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ PHP 8.6 UPGRADE NOTES
201201
message includes the function name and argument index ($modulus).
202202

203203
- Intl:
204-
. IntlDateFormatter::formatObject() now accepts objects that support
205-
numeric casting as date/time values, in addition to IntlCalendar and
206-
DateTimeInterface instances.
204+
. IntlDateFormatter::format() now accepts objects that support numeric
205+
casting as date/time values.
207206

208207
- mysqli:
209208
. The return structure of mysqli_get_charset() no longer contains

ext/intl/common/common_date.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err)
205205
zval casted;
206206
ZVAL_UNDEF(&casted);
207207

208-
if (Z_OBJ_HT_P(z)->cast_object(Z_OBJ_P(z), &casted, _IS_NUMBER) == SUCCESS) {
208+
if (Z_OBJ_HT_P(z)->cast_object(Z_OBJ_P(z), &casted, _IS_NUMBER) == SUCCESS
209+
&& !EG(exception)) {
209210
if (Z_TYPE(casted) == IS_LONG) {
210211
rv = U_MILLIS_PER_SECOND * (double)Z_LVAL(casted);
211212
} else if (Z_TYPE(casted) == IS_DOUBLE) {
@@ -214,10 +215,12 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err)
214215
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
215216
"invalid object type for date/time");
216217
}
217-
zval_ptr_dtor(&casted);
218218
} else {
219219
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
220-
"invalid object type for date/time ");
220+
"invalid object type for date/time");
221+
}
222+
if (!Z_ISUNDEF(casted)) {
223+
zval_ptr_dtor(&casted);
221224
}
222225
}
223226
break;

ext/intl/tests/dateformat_formatObject_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var_dump(IntlDateFormatter::formatObject($cal, ""));
4040
var_dump(intl_get_error_message());
4141

4242
?>
43-
--EXPECT--
43+
--EXPECTF--
4444
DateObjectError: Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
4545
bool(false)
4646
string(130) "IntlDateFormatter::formatObject(): the passed object must be an instance of either IntlCalendar or DateTimeInterface: U_ZERO_ERROR"

ext/intl/tests/dateformat_formatObject_numeric_object.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
IntlDateFormatter::formatObject(): numeric-castable objects
2+
IntlDateFormatter->format(): numeric-castable objects
33
--EXTENSIONS--
44
intl
55
zend_test
@@ -9,10 +9,10 @@ date.timezone=UTC
99
--FILE--
1010
<?php
1111

12-
$format = 'yyyy-MM-dd HH:mm:ss.SSS';
12+
$fmt = new IntlDateFormatter('en_US', IntlDateFormatter::NONE, IntlDateFormatter::NONE, 'UTC', null, 'yyyy-MM-dd HH:mm:ss.SSS');
1313

14-
echo IntlDateFormatter::formatObject(new NumericCastableNoOperations(0), $format, 'en_US'), "\n";
15-
echo IntlDateFormatter::formatObject(new NumericCastableNoOperations(0.5), $format, 'en_US'), "\n";
14+
echo $fmt->format(new NumericCastableNoOperations(0)), "\n";
15+
echo datefmt_format($fmt, new NumericCastableNoOperations(0.5)), "\n";
1616

1717
?>
1818
--EXPECT--

ext/intl/tests/dateformat_format_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var_dump($v);
1919
var_dump(intl_get_error_message());
2020

2121
?>
22-
--EXPECT--
22+
--EXPECTF--
2323
bool(false)
24-
string(140) "IntlDateFormatter::format(): invalid object type for date/time (only IntlCalendar and DateTimeInterface permitted): U_ILLEGAL_ARGUMENT_ERROR"
24+
string(%d) "IntlDateFormatter::format(): invalid object type for date/time: U_ILLEGAL_ARGUMENT_ERROR"
2525
bool(false)
26-
string(129) "datefmt_format(): invalid object type for date/time (only IntlCalendar and DateTimeInterface permitted): U_ILLEGAL_ARGUMENT_ERROR"
26+
string(%d) "datefmt_format(): invalid object type for date/time: U_ILLEGAL_ARGUMENT_ERROR"

0 commit comments

Comments
 (0)