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

PHP 8.2 - utf8_encode deprecated #2630

Closed
systemsolutionweb opened this issue Jun 20, 2022 · 1 comment · Fixed by #2632
Closed

PHP 8.2 - utf8_encode deprecated #2630

systemsolutionweb opened this issue Jun 20, 2022 · 1 comment · Fixed by #2632
Milestone

Comments

@systemsolutionweb
Copy link

Hello,

I encountered an issue with the following code:
utf8_encode() deprecated

return static::$utf8 ? utf8_encode($formatted) : $formatted;

Carbon version: latest

PHP version: 8.2

https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated

Suggestion:

return static::$utf8 ? (function_exists('mb_convert_encoding') ?
    mb_convert_encoding($formatted, 'UTF-8', mb_list_encodings()) :
    utf8_encode($formatted)) : $formatted;

Thanks!

@kylekatarnls kylekatarnls added this to the 2.60.0 milestone Jun 27, 2022
@kylekatarnls
Copy link
Collaborator

Hi, thanks for the report. mb_convert_encoding is recommended as a replacement in the official documentation so your suggestion is good.

As the Carbon method formatLocalized it's in is also deprecated, we'll get rid of all that in a later version.

Would you mind to create a pull-request for it?

Maybe indent both ternary for readability:

return static::$utf8
    ? (function_exists('mb_convert_encoding')
        ? mb_convert_encoding($formatted, 'UTF-8', mb_list_encodings())
        : utf8_encode($formatted)
    )
    : $formatted;

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

Successfully merging a pull request may close this issue.

2 participants