|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[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
[2021-02-17 16:32 UTC] cmb@php.net
[2021-02-17 16:32 UTC] cmb@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 15:00:01 2025 UTC |
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