php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80671 mb_convert_encoding() throws ValueError on invalid encoding
Submitted: 2021-01-26 07:37 UTC Modified: 2021-01-26 19:03 UTC
From: alec at alec dot pl Assigned:
Status: Closed Package: mbstring related
PHP Version: 8.0.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 - 23 = ?
Subscribe to this entry?

 
 [2021-01-26 07:37 UTC] alec at alec dot pl
Description:
------------
PHP Fatal error:  Uncaught ValueError: mb_convert_encoding(): Argument #3 ($from_encoding) contains invalid encoding "WINDOWS-1253".

Before PHP8 it never threw even a warning, so to me it looks like a BC break which:
1. should throw a warning in PHP 8.0, before it could switch to a fatal error in 8.1.
2. should be mentioned in the migration guide and the documentation.

Reference: https://github.com/roundcube/roundcubemail/issues/7850

Test script:
---------------
<?php
mb_convert_encoding("test", "UTF-8", "WINDOWS-1253");



Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-26 07:39 UTC] alec at alec dot pl
BTW, regarding the error message, the encoding is not invalid, it is unsupported.
 [2021-01-26 08:50 UTC] nikic@php.net
-Type: Bug +Type: Documentation Problem
 [2021-01-26 13:34 UTC] nikic@php.net
-Summary: mb_convert_encoding() throws ValueError unexpectedly +Summary: mb_convert_encoding() throws ValueError on invalid encoding
 [2021-01-26 13:34 UTC] nikic@php.net
As expected, this already threw a warning since at least PHP 4.3: https://3v4l.org/5cErI

A changelog entry that this throws a ValueError exception since PHP 8.0 is missing through.
 [2021-01-26 18:52 UTC] alec at alec dot pl
All right, it looks I was mistaken about no warning in earlier versions, but since Roundcube exists I've never saw such a warning (and we're dealing with all kinds of "invalid" encodings). Maybe that has something to do with removal of some code path that was using iconv() before mbstring methods.

So, it is a documentation problem.
 [2021-05-01 14:03 UTC] hallberg dot kim at gmail dot com
The following pull request has been associated:

Patch Name: [80671] Update `mb_convert_encoding`.
On GitHub:  https://github.com/php/doc-en/pull/582
Patch:      https://github.com/php/doc-en/pull/582.patch
 [2021-05-03 08:52 UTC] git@php.net
Automatic comment on behalf of thinkverse (author) and web-flow (committer)
Revision: https://github.com/php/doc-en/commit/c9893954e17ec13bf66f54433e72c8af026406cf
Log: Fix #80671: Update `mb_convert_encoding`
 [2021-05-03 08:52 UTC] git@php.net
-Status: Open +Status: Closed
 [2021-05-03 10:43 UTC] git@php.net
Automatic comment on behalf of mumumu
Revision: https://github.com/php/doc-ja/commit/64b6ceceff9238e1b8d2ba435f80c5b8526ff75f
Log: Fix #80671: Update mb_convert_encoding
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 15 10:01:24 2021 UTC