php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58631 MessageFormatter Constructor Returns Null
Submitted: 2009-04-14 11:04 UTC Modified: 2012-04-21 10:33 UTC
From: kermodebear at gmail dot com Assigned:
Status: Wont fix Package: intl (PECL)
PHP Version: 5.2.8 OS: Linux 2.6.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
16 + 22 = ?
Subscribe to this entry?

 
 [2009-04-14 11:04 UTC] kermodebear at gmail dot com
Description:
------------
The MessageFormatter constructor returns null when using an invalid format string.

Reproduce code:
---------------
<?php
$example = new MessageFormatter('en_US', '{0,oops}');
var_dump($example);
?>

Expected result:
----------------
I expected to receive a MessageFormatter object. The output of the script above should be:

object(MessageFormatter)#1 (0) {
}

An invalid token in the format string should be ignored, possibly with an a error triggered, and a valid object returned. 

Alternately, an InvalidArgumentException exception could be thrown.

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-18 20:56 UTC] will dot skates at ntlworld dot com
The list of valid patterns can be found here: http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html. Check that your pattern is valid before attempting to create the object. 

You are correct however that a catchable exception should be thrown when you attempt to create it, could someone please write a patch for this?
 [2012-04-21 10:33 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2012-04-21 10:33 UTC] cataphract@php.net
The current standard behavior in intl is returning NULL on constructor errors. This may change in the future, but I don't see a strong need for such change in behavior.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Mar 31 20:01:24 2020 UTC