php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65163 Collator::__construct inconsistency between doc and implementation
Submitted: 2013-06-28 21:13 UTC Modified: 2014-06-08 23:24 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: poinsot dot julien at gmail dot co Assigned: stas (profile)
Status: Closed Package: I18N and L10N related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2013-06-28 21:13 UTC] poinsot dot julien at gmail dot co
Description:
------------
There is an inconsistency between current PHP implemention and the documentation about Collator::__construct, Collator::create and collator_create.

It says:

Special values for locales can be passed in - if null is passed for the locale, the default locale collation rules will be used. If empty string ("") or "root" are passed, UCA rules will be used.

But actual implementation of collator_ctor in ext/intl/collator/collator_create.c does not check type of its parameter:

if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &locale, &locale_len ) == FAILURE )
/* ... */
if(locale_len == 0) {
    locale = intl_locale_get_default(TSRMLS_C);
}

So, for PHP, a NULL value as an empty string imply the default locale.

Test script:
---------------
ini_set('intl.default_locale', fr_CA);

$coll = new Collator('');
var_dump(
    $coll->getLocale(Locale::VALID_LOCALE)
);

Expected result:
----------------
string(4) "root"

Actual result:
--------------
string(5) "fr_FR"

Patches

collator_create (last revision 2013-06-28 21:14 UTC by poinsot dot julien at gmail dot co)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-15 00:38 UTC] felipe@php.net
-Status: Open +Status: Assigned -Package: intl +Package: I18N and L10N related -Assigned To: +Assigned To: stas
 [2014-06-08 23:06 UTC] stas@php.net
-Type: Bug +Type: Documentation Problem
 [2014-06-08 23:06 UTC] stas@php.net
I think, given how long it has been the case, and that all other classes see "" and null as the same, it's better to fix the docs to state "" and null are the same and "root" is UCA rules. This would not remove any functionality - "root" still works - but would make intl more consistent.
 [2014-06-08 23:24 UTC] stas@php.net
Automatic comment from SVN on behalf of stas
Revision: http://svn.php.net/viewvc/?view=revision&revision=333736
Log: Fix bug #65163: match the docs to the code
 [2014-06-08 23:24 UTC] stas@php.net
-Status: Assigned +Status: Closed
 [2014-06-08 23:24 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2020-02-07 06:08 UTC] phpdocbot@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=e2c5537e4425ce9e305d34289de5f963276e0af2
Log: Fix bug #65163: match the docs to the code
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 20:01:29 2024 UTC