php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80763 MessageFormatter::format() can't accept date arguments after array_walk()
Submitted: 2021-02-17 11:14 UTC Modified: 2021-02-17 13:06 UTC
From: denis_chernyaev at behappy2day dot com Assigned: cmb (profile)
Status: Closed Package: intl (PECL)
PHP Version: 7.4.15 OS: Windows Server 2012 R2
Private report: No CVE-ID: None
 [2021-02-17 11:14 UTC] denis_chernyaev at behappy2day dot com
Description:
------------
Using array_walk() on parameters prior to sending them to MessageFormatter::format breaks date parameters and causes an error. Doesn't matter if you pass a \DateTimeInterface or an integer timestamp.

Test script:
---------------
$today = new DateTime();
$formatter = new \MessageFormatter('en_US', 'Today is {today, date, full}.');
$params = ['today' => $today];
array_walk($params, fn() => 1);
var_dump($params);
if($str = $formatter->format($params)) {
    echo $str;
} else {
    echo sprintf('Unable to format message (error #%s): ', $formatter->getErrorCode()) . $formatter->getErrorMessage();
}

Expected result:
----------------
array(1) {
  ["today"]=>
  object(DateTime)#12 (3) {
    ["date"]=>
    string(26) "2021-02-17 14:10:54.229580"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(13) "Europe/Moscow"
  }
}
Today is Wednesday, February 17, 2021.

Actual result:
--------------
array(1) {
  ["today"]=>
  object(DateTime)#12 (3) {
    ["date"]=>
    string(26) "2021-02-17 14:10:54.229580"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(13) "Europe/Moscow"
  }
}
Unable to format message (error #1): The argument for key 'today' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-17 13:06 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-02-17 13:09 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #80763: msgfmt_format() does not accept DateTime references
On GitHub:  https://github.com/php/php-src/pull/6707
Patch:      https://github.com/php/php-src/pull/6707.patch
 [2021-02-17 16:32 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=84b615284218736f4fe2450a5f43ef61f2a78901
Log: Fix #80763: msgfmt_format() does not accept DateTime references
 [2021-02-17 16:32 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC