Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mb_detect_encoding difference between PHP 8.1.28 and 8.3.6 #14226

Closed
staabm opened this issue May 14, 2024 · 3 comments
Closed

mb_detect_encoding difference between PHP 8.1.28 and 8.3.6 #14226

staabm opened this issue May 14, 2024 · 3 comments

Comments

@staabm
Copy link
Contributor

staabm commented May 14, 2024

Description

The following code:

<?php

var_dump(mb_detect_encoding("CMS-Seite l\xF6schen"));

Resulted in this output on 8.1.28:

bool(false)

Resulted in this output on 8.3.6:

string(5) "ASCII"

https://3v4l.org/TY6vO

But I expected: no sure what to expect and which one is right/wrong ;)

PHP Version

8.3.6

Operating System

Ubuntu24.04 lts

@staabm
Copy link
Contributor Author

staabm commented May 14, 2024

//cc @alexdowad

@damianwadley
Copy link
Member

This is documented in the 8.3 migration guide:

https://www.php.net/manual/en/migration83.other-changes.php

mb_detect_encoding()'s "non-strict" mode now behaves as described in the documentation. Previously, it would return false if the same byte (for example, the first byte) of the input string was invalid in all candidate encodings. More generally, it would eliminate candidate encodings from consideration when an invalid byte was seen, and if the same input byte eliminated all remaining encodings still under consideration, it would return false. On the other hand, if all candidate encodings but one were eliminated from consideration, it would return the last remaining one without regard for how many encoding errors might be encountered later in the string. This is different from the behavior described in the documentation, which says: "If strict is set to false, the closest matching encoding will be returned."

If you want an exact-or-nothing match then use the $strict parameter. https://3v4l.org/bLYlB

@damianwadley damianwadley closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@staabm
Copy link
Contributor Author

staabm commented May 14, 2024

great catch - thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants