Bug #61244 [Com]: Translitrator __construct should be like create
Edit report at https://bugs.php.net/bug.php?id=61244&edit=1
ID: 61244
Comment by: jinmoku at hotmail dot com
Reported by: jinmoku at hotmail dot com
Summary: Translitrator __construct should be like create
Status: Wont fix
Type: Bug
Package: I18N and L10N related
Operating System: Windows 7
PHP Version: 5.4.0
Block user comment: N
Private report: N
New Comment:
I understand, but you should change the documentation
Previous Comments:
------------------------------------------------------------------------
[2012-03-02 21:44:48] cataphract@php.net
The reason for not exposing a public constructor is that this gives a little more latitude for
building, in the future, a proper inheritance interface.
Factory methods are more versatile than constructors because they can return different class types.
In the future, we may want to expose subclasses of Transliterator. Let's say that the
transliterator 'NFD' has, in ICU, a specific C++ type (class) with more methods. With a
factory method we can return a PHP class that exposes these additional C++ methods, while with a
constructor we couldn't.
------------------------------------------------------------------------
[2012-03-02 14:02:36] jinmoku at hotmail dot com
Description:
------------
Translitrator __construct should be like create
Test script:
---------------
$trans = new Transliterator('NFD; [:Nonspacing Mark:] Remove; NFC');
echo $trans->transliterate('hé');
Expected result:
----------------
he
Actual result:
--------------
Fatal error: Call to private Transliterator::__construct() from invalid context in
D:\www\test\index.php on line 4
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61244&edit=1
Thread (3 messages)