note 115841 added to class.messageformatter

From: Date: Thu, 02 Oct 2014 10:18:10 +0000
Subject: note 115841 added to class.messageformatter
Groups: php.notes 
Request: Send a blank email to php-notes+get-200565@lists.php.net to get a copy of this message
MessageFormatter does not work with DateTime instances as parameters in PHP < 5.5. Instance will be converted to timestamp with value 0 (e.g. 1970-01-01) and following Notice will be raised: „Object of class DateTime could not be converted to int“. You have to manually convert the instance to timestamp in these old PHP versions. <?php $datetime = new DateTime(); if (PHP_VERSION_ID < 50500) { // PHP < 5.5 needs conversion to timestamp MessageFormatter::formatMessage('en_US', 'Today is {0, date, full}.', array($datetime->getTimestamp())); } else { // current code MessageFormatter::formatMessage('en_US', 'Today is {0, date, full}.', array($datetime)); } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 2a00:c500:204:2368:49e5:d314:cacd:b73 ---- Manual Page -- http://php.net/manual/en/class.messageformatter.php Edit -- https://master.php.net/note/edit/115841 Del: integrated -- https://master.php.net/note/delete/115841/integrated Del: useless -- https://master.php.net/note/delete/115841/useless Del: bad code -- https://master.php.net/note/delete/115841/bad+code Del: spam -- https://master.php.net/note/delete/115841/spam Del: non-english -- https://master.php.net/note/delete/115841/non-english Del: in docs -- https://master.php.net/note/delete/115841/in+docs Del: other reasons-- https://master.php.net/note/delete/115841 Reject -- https://master.php.net/note/reject/115841 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200565) next »