php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70676 MessageFormatter fails completely in certain situations
Submitted: 2015-10-09 10:54 UTC Modified: 2016-04-11 13:36 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: mh-php at outlook dot de Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: 5.4.45 OS: Linux 4.1.0-2-amd64 #1 SMP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mh-php at outlook dot de
New email:
PHP Version: OS:

 

 [2015-10-09 10:54 UTC] mh-php at outlook dot de
Description:
------------
Some combinations in the pattern string the MessageFormatter class completely fails returning null on object initialization and fails with bogus exception message on format().

Using the newest PECL module available.

intl
Internationalization support: enabled
version: PECL-3.0.0
ICU version: 55.1
ICU Data version: 55.1

Test script:
---------------
$msg = new MessageFormatter( "de_DE", "This is a number - {0,number}." );
var_dump( $msg->format( [ 654.987 ] ) );
$msg = new MessageFormatter( "de_DE", "This is an integer - {0,number,integer}." );
var_dump( $msg->format( [ 654.987 ] ) );
$msg = new MessageFormatter( "de_DE", "This is a combined number - {0,number} , {0,number,integer}." );
var_dump( $msg ); // $msg = null -> Fatal error: Call to a member function format() on a non-object, calling getErrorCode() is impossible
if( $msg !== null ) var_dump( $msg->format( [ 654.987 ] ) ); // never dumps anything

var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount}", [ "itemCount" => 5 ] ) );
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) );
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount} {itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) ); // FAILS: why ...?
var_dump( MessageFormatter::formatMessage( "de_DE", "{itemCount,number} {itemCount, plural, one {item} other {items} }", [ "itemCount" => 5 ] ) ); // doesn't fail

var_dump( MessageFormatter::formatMessage( "en_US", "this is an unlocalized string {0,date}.", [ time() ] ) );
var_dump( MessageFormatter::formatMessage( "en_US", "this is an unlocalized string {0,date}.", [ new DateTime( "now" ) ] ) );
var_dump( MessageFormatter::formatMessage( "en_US", "this is an already localized string Oct 9, 2015.", [ time() ] ) );
$m = new MessageFormatter( "en_US", "this is an already localized string Oct 9, 2015." );
$m->format( [ new DateTime( "now" ) ] ); // Catchable fatal error: Object of class DateTime could not be converted to string


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-11 13:36 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2016-04-11 13:36 UTC] ab@php.net
"This is a combined number - {0,number} , {0,number,integer}." - same numeric key specified twice. 
->format( [ new DateTime( "now" ) ] ) - but you miss {0, date} in the format

As well as other places - you use a wrong format or missing placeholders.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC