Fix #80763: msgfmt_format() does not accept DateTime references

`intl_zval_to_millis()` needs to cater to references.

Closes GH-6707.
This commit is contained in:
Christoph M. Becker 2021-02-17 14:05:28 +01:00
parent 9552cf6b84
commit 84b6152842
3 changed files with 24 additions and 0 deletions

4
NEWS
View File

@ -2,6 +2,10 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2021, php 7.4.17 ?? ??? 2021, php 7.4.17
- Intl:
. Fixed bug #80763 (msgfmt_format() does not accept DateTime references).
(cmb)
- MySQLnd: - MySQLnd:
. Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and . Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and
MySQL 8.0). (Nikita) MySQL 8.0). (Nikita)

View File

@ -175,6 +175,7 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func)
return ZEND_NAN; return ZEND_NAN;
} }
try_again:
switch (Z_TYPE_P(z)) { switch (Z_TYPE_P(z)) {
case IS_STRING: case IS_STRING:
type = is_numeric_string(Z_STRVAL_P(z), Z_STRLEN_P(z), &lv, &rv, 0); 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)
efree(message); efree(message);
} }
break; break;
case IS_REFERENCE:
z = Z_REFVAL_P(z);
goto try_again;
default: default:
spprintf(&message, 0, "%s: invalid PHP type for date", func); spprintf(&message, 0, "%s: invalid PHP type for date", func);
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,

View File

@ -0,0 +1,16 @@
--TEST--
Bug #80763 (msgfmt_format() does not accept DateTime references)
--SKIPIF--
<?php
if (!extension_loaded('intl')) die('skip intl extension not available');
?>
--FILE--
<?php
$today = new DateTime('2021-02-17 12:00:00');
$formatter = new \MessageFormatter('en_US', 'Today is {today, date, full}.');
$params = ['today' => $today];
array_walk($params, fn() => 1);
var_dump($formatter->format($params));
?>
--EXPECT--
string(38) "Today is Wednesday, February 17, 2021."