|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52776 MessageFormatter::__construct should throw an exception for invalid patterns
Submitted: 2010-09-04 23:23 UTC Modified: 2015-08-07 00:55 UTC
Avg. Score:4.7 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: clicky at erebot dot net Assigned: danack (profile)
Status: Closed Package: I18N and L10N related
PHP Version: Irrelevant OS: Ubuntu 9.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: clicky at erebot dot net
New email:
PHP Version: OS:


 [2010-09-04 23:23 UTC] clicky at erebot dot net
MessageFormatter's constructor returns NULL when an invalid pattern is given.
Instead, it should throw an exception.

This bug has already been reported twice before (see #52042 & #49161). Each time the report was marked as bogus because the real problem got overlooked. (the problem lies not in the given pattern being considered invalid by ICU, the problem is in the constructor returning NULL)

Test script:

$f1 = msgfmt_create('en_US', '{this was made intentionally incorrect}');
echo 'f1 is ', gettype($f1), PHP_EOL;

$f2 = MessageFormatter::create('en_US', '{this was made intentionally incorrect}');
echo 'f2 is ', gettype($f2), PHP_EOL;

$f3 = new MessageFormatter('en_US', '{this was made intentionally incorrect}');
echo 'f3 is ', gettype($f3), PHP_EOL;


Expected result:
f1 is NULL
f2 is NULL
Fatal error: Uncaught exception 'Exception' with message 'Invalid pattern' in %s:%d.

Actual result:
f1 is NULL
f2 is NULL
f3 is NULL


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-05 23:34 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: stas
 [2011-04-17 23:58 UTC]
-Package: *Languages/Translation +Package: I18N and L10N related
 [2011-04-17 23:58 UTC]
-Type: Bug +Type: Feature/Change Request
 [2012-02-21 10:20 UTC] jinmoku at hotmail dot com
use the ini directive : intl.error_level
 [2012-02-26 12:05 UTC] clicky at erebot dot net
jinmoku at hotmail dot com:

Please read the report again. The documentation on the new operator ( states:

"To create an instance of a class, the new keyword must be used. An object will always be created unless the object has a constructor defined that throws an exception on error."

In the context of the "new" keyword, ONLY exceptions may be used to signal errors. In intl's case, "new" returns NULL on errors, which clearly is a bug per the documentation above, regardless of any INI setting the extension may otherwise provide to later change the way it signals errors.

Sorry if I sound rude, but this bug has already been overlooked twice.

Anyway, this bug will probably not be resolved any time soon due to stas' involvement with PHP 5.4. I'm slowly learning about core internals and will try to come up with a patch for this issue when I feel comfortable enough.
 [2013-02-17 10:46 UTC]
-Assigned To: stas +Assigned To:
 [2015-01-15 20:34 UTC]
-Assigned To: +Assigned To: danack
 [2015-01-15 20:34 UTC]
I'm going to look at this - I think it ought to be fixed for 7.
 [2015-05-08 08:57 UTC] clicky at erebot dot net
Thanks for looking into this Dan.

I see your RFC on "Constructor behaviour of internal classes" passed and was merged in. I also saw;a=commitdiff;h=e96616739c2414947197a67fe8af6da594b34762;hp=dd0b602381fad375d8f29a97f25f099be7c9db35 which seems to fix this issue as well as #52776.

I'll try to test this against master soon and report the results here.
 [2015-08-07 00:55 UTC]
-Status: Assigned +Status: Closed
 [2015-08-07 00:55 UTC]
This issue has been resolved with PHP 7, see
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 31 00:03:42 2023 UTC