php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60429 utf8_encode and utf8_decode functions should be deprecated
Submitted: 2011-12-02 01:37 UTC Modified: 2018-08-26 16:38 UTC
Votes:9
Avg. Score:3.0 ± 1.6
Reproduced:5 of 7 (71.4%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: deceze at gmail dot com Assigned:
Status: Suspended Package: *XML functions
PHP Version: Irrelevant OS:
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: deceze at gmail dot com
New email:
PHP Version: OS:

 

 [2011-12-02 01:37 UTC] deceze at gmail dot com
Description:
------------
The purpose of the functions utf8_encode and utf8_decode are time and again 
misunderstood and have probably caused more encoding related problems than they 
have solved. The biggest reason for this is their naming. Their purpose is to 
*convert* the encoding of a string from ISO-8859-1 to UTF-8, yet they are named 
in a way that suggests some other magical function that is necessary to work 
with UTF-8 text. Users looking for "UTF-8 support" in their app quickly find 
these functions due to their naming and use them without understanding what they 
do, often only testing with ASCII text which appears to work fine of first 
sight.

Why is ISO-8859-1 presumed to be the default encoding when converting to UTF-8, 
hence why do these functions occupy such a prominent spot in the namespace? 
There's simply no good reason for it.

The same functionality is available through iconv and mb_convert_encoding. 
Therefore I suggest to slowly deprecate utf8_encode and utf8_decode to clear up 
a recurring confusion and consolidate features into the existing, much more 
versatile iconv and mb_ functions.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-30 02:58 UTC] yohgaki@php.net
-Assigned To: +Assigned To: yohgaki
 [2016-08-22 14:21 UTC] daniel-php at easetechnology dot co dot uk
Additionally, utf_encode and utf8_decode appear to be part of the XML extension, and it shouldn't be necessary to include an XML parser just for two character conversion functions.
 [2017-10-24 08:02 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: yohgaki +Assigned To:
 [2018-08-26 16:38 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2018-08-26 16:38 UTC] cmb@php.net
Deprecating existing functions requires the RFC process.  There is
already a respective RFC[1], albeit it seems to have been
abandoned.  Anyhow, for the time being, I'm suspending this
ticket.

Note also that utf8_decode() and utf8_encode() are no longer part
of the XML extension, but are standard functions as of PHP
7.2.0[2].

[1] <https://wiki.php.net/rfc/remove_utf_8_decode_encode>
[2] <https://github.com/php/php-src/pull/2160>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC