Skip to content

Commit 84b6152

Browse files
committed
Fix #80763: msgfmt_format() does not accept DateTime references
`intl_zval_to_millis()` needs to cater to references. Closes GH-6707.
1 parent 9552cf6 commit 84b6152

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, php 7.4.17
44

5+
- Intl:
6+
. Fixed bug #80763 (msgfmt_format() does not accept DateTime references).
7+
(cmb)
8+
59
- MySQLnd:
610
. Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and
711
MySQL 8.0). (Nikita)

ext/intl/common/common_date.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func)
175175
return ZEND_NAN;
176176
}
177177

178+
try_again:
178179
switch (Z_TYPE_P(z)) {
179180
case IS_STRING:
180181
type = is_numeric_string(Z_STRVAL_P(z), Z_STRLEN_P(z), &lv, &rv, 0);
@@ -227,6 +228,9 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func)
227228
efree(message);
228229
}
229230
break;
231+
case IS_REFERENCE:
232+
z = Z_REFVAL_P(z);
233+
goto try_again;
230234
default:
231235
spprintf(&message, 0, "%s: invalid PHP type for date", func);
232236
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,

ext/intl/tests/bug80763.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #80763 (msgfmt_format() does not accept DateTime references)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die('skip intl extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$today = new DateTime('2021-02-17 12:00:00');
10+
$formatter = new \MessageFormatter('en_US', 'Today is {today, date, full}.');
11+
$params = ['today' => $today];
12+
array_walk($params, fn() => 1);
13+
var_dump($formatter->format($params));
14+
?>
15+
--EXPECT--
16+
string(38) "Today is Wednesday, February 17, 2021."

0 commit comments

Comments
 (0)