php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66108 Setting locale to 'tr_TR' lowercases parts of constants
Submitted: 2013-11-17 18:41 UTC Modified: 2015-04-01 21:06 UTC
Votes:6
Avg. Score:4.5 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:4 (66.7%)
From: t dot baumgarden at web dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.6 OS: CentOS 6
Private report: No CVE-ID: None
 [2013-11-17 18:41 UTC] t dot baumgarden at web dot de
Description:
------------
Hi. The (same?) bug was closed long time before here: https://bugs.php.net/bug.php?id=18556

Now its back in php 5.5.6.

Write

setlocale(LC_ALL, 'tr_TR.UTF-8');

I get:

constant(): Couldn't find constant test::PRODUCTiON

and complete page is broken.

See "i" in "PRODUCTiON". Change 'tr_TR.UTF-8' to another string like 'en_US.UTF-8' now its working fine.

Test script:
---------------
class test {
	const PRODUCTION  = 20;
    public static $environment = 10;
}
test::$environment = constant('test::'.strtoupper('production'));
echo (test::$environment);


Expected result:
----------------
20

Actual result:
--------------
Error message: constant(): Couldn't find constant test::PRODUCTiON

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-17 18:57 UTC] t dot baumgarden at web dot de
In short:

setlocale(LC_ALL, 'tr_TR.UTF-8');
echo strtoupper('production');

Result: "PRODUCTiON" with wrong "i"
 [2014-09-10 14:51 UTC] chuanm at gmail dot com
I think this bug also affects preg_match() function while using the case insensitive match modifier. Seems only letter 'i' has the problem. See example below: 

<?php

setlocale(LC_ALL, 'tr_TR.UTF-8');
var_dump(preg_match('/I/i', 'production'));   // output: no match found (WRONG)
var_dump(preg_match('/O/i', 'production'));   // output: one match found (correct)
 [2014-09-10 15:04 UTC] chuanm at gmail dot com
The bug doesn't exist in php 5.4.31. So it could be introduced in php 5.5. The nasty part of this bug is that a locale change would affect how php handles some "English" letter.
 [2015-02-26 10:56 UTC] jpauli@php.net
PHP's strtolower() has always been locale aware and works the same in 5.4 and 5.5.
Did I miss something ?
 [2015-04-01 21:06 UTC] stas@php.net
-Status: Open +Status: Not a bug
 [2015-04-01 21:06 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not the same as #18556 as you are manually using "strtoupper", which is locale-dependent, so it does what you asked it to do - provides the locale-dependent uppercase rendering of "production". Unfortunately, in tr_TR the uppercase of "production" is "PRODUCTÄ°ON" and not "PRODUCTION". If you must use this locale, I'd suggest using mb_strtoupper or mb_convert_case.
 [2015-04-02 07:30 UTC] t dot baumgarden at web dot de
You are right in PHP 5.3 (tested with online php)
But in PHP 5.6.3 (I acutal use) this bug is gone and all working fine.

setlocale(LC_ALL, 'tr_TR.UTF-8');
echo strtoupper('production');

show me "PRODUCTION" and not what you said "PRODUCTÄ°ON".

Why in PHP 5.6.3 this now working with "strtoupper"?
In PHP 5.3 its working only with "mb_strtoupper".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC