Req #52776 [Opn]: MessageFormatter::__construct should throw an exception for invalid patterns
| From: | danack@php.net | Date: | Thu, 15 Jan 2015 20:34:09 +0000 |
| Subject: | Req #52776 [Opn]: MessageFormatter::__construct should throw an exception for invalid patterns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189978@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52776&edit=1
ID: 52776
Updated by: danack@php.net
Reported by: clicky at erebot dot net
Summary: MessageFormatter::__construct should throw an
exception for invalid patterns
Status: Open
Type: Feature/Change Request
Package: I18N and L10N related
Operating System: Ubuntu 9.10
PHP Version: Irrelevant
-Assigned To:
+Assigned To: danack
Block user comment: N
Private report: N
New Comment:
I'm going to look at this - I think it ought to be fixed for 7.
Previous Comments:
------------------------------------------------------------------------
[2012-02-26 12:05:42] clicky at erebot dot net
jinmoku at hotmail dot com:
Please read the report again. The documentation on the new operator
(http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new) 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.
------------------------------------------------------------------------
[2012-02-21 10:20:52] jinmoku at hotmail dot com
use the ini directive : intl.error_level
------------------------------------------------------------------------
[2010-09-04 23:23:04] clicky at erebot dot net
Description:
------------
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:
---------------
<?php
$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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52776&edit=1