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

Polyfill utf8_encode use for php8.2+ compatibility #1415

Closed
elhardoum opened this issue Dec 27, 2022 · 1 comment
Closed

Polyfill utf8_encode use for php8.2+ compatibility #1415

elhardoum opened this issue Dec 27, 2022 · 1 comment
Assignees
Labels

Comments

@elhardoum
Copy link

Describe the bug

With php8.2 released a couple weeks ago, and since this library supports "php": ">=5.6.0", I think it's time to add a polyfill for the deprecated function utf8_encode:

return \utf8_encode($value);

Symfony has a nice polyfill library that can be used: https://github.com/symfony/polyfill/blob/-/src/Php72/Php72.php#L24

To Reproduce

  1. Use php8.2
  2. Run the unit tests, or simply call \Stripe\Util\Util::utf8('test')

Expected behavior

It should throw a deprecation notice error

Code snippets

No response

OS

macOS

PHP version

PHP 8.2

Library version

latest

API version

latest

Additional context

No response

@anniel-stripe
Copy link
Contributor

anniel-stripe commented Jan 3, 2023

Thanks for flagging!

I've opened a PR to address this by following the steps in https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated#utf8_encode-any-mbstring , since I believe we actually want to convert any string to UTF-8 encoding, not just those encoded in ISO-8859-1.

Edit: Looks like the encoding detection is imperfect, so switched to https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated#utf8_encode-iso8859-mbstring instead.

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

No branches or pull requests

2 participants