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

Utils - Add multibyte and UTF-8 support #6054

Merged
merged 1 commit into from
Oct 11, 2021

Conversation

paulbalandan
Copy link
Contributor

Fixes #5297

@coveralls
Copy link

coveralls commented Oct 6, 2021

Coverage Status

Coverage increased (+0.009%) to 92.828% when pulling d3637aa on paulbalandan:utils-multibyte into 3968d73 on FriendsOfPHP:master.

@SpacePossum
Copy link
Contributor

Hi and thanks for the PR!

Currently we don't require the mb_ext , nor do we pollyfil it. Not sure what would be best way forward, making it a requirement, polyfil it using the SF package or adding a function_exist() check with a fallback with maybe a custom solution.
Thoughts @keradus , @julienfalque @kubawerlos ?

@keradus
Copy link
Member

keradus commented Oct 6, 2021

if we need mb_* support, i would require polyfill

@julienfalque
Copy link
Member

I have no strong opinion about this. Requiring the polyfill would increase the tool's weight but the extension might not be widespread enough to avoid it. Anyway, whatever choice we make, it should be required in composer.json.

@SpacePossum
Copy link
Contributor

SpacePossum commented Oct 10, 2021

I know this looks like scope creep, yet I feel like if we go this way we should take care of some other points in the code effected by this as well.

There are a few spots we do function_exists('mb_*. With the polyfil now added we should check if these will now always return true. We have to check if these have no unwanted side effects (for example if the polyfil does not behave exactly as the extension).

Places are:

For the last one, MbStrFunctionsFixer, I think that one is already good as it checks if the functions are internal.

Btw. nice work on updating the regex, so close to RTM from me :)

@SpacePossum
Copy link
Contributor

Thank you @paulbalandan.

@SpacePossum SpacePossum merged commit c4989f8 into PHP-CS-Fixer:master Oct 11, 2021
@paulbalandan paulbalandan deleted the utils-multibyte branch October 11, 2021 05:01
@@ -58,7 +58,7 @@ public function __construct()
$this->functions = array_filter(
self::$functionsMap,
static function (array $mapping): bool {
return \function_exists($mapping['alternativeName']) && (new \ReflectionFunction($mapping['alternativeName']))->isInternal();
return (new \ReflectionFunction($mapping['alternativeName']))->isInternal();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for why the check with function_exists was removed? This seems to be a BC break on PHP 7.3.

Uncaught ReflectionException: Function mb_str_split() does not exist in vendor/friendsofphp/php-cs-fixer/src/Fixer/Alias/MbStrFunctionsFixer.php:61

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symfony/polyfill-mbstring was added as a dependency so this should not happen. How did you install PHP CS Fixer?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @julienfalque,

Well I'm removing polyfills when the extension is mandatory. I'm the only one who is doing this?

For example

{
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "php": "^7.3",
        "ext-ctype": "*",
        "ext-mbstring": "*",
        "friendsofphp/php-cs-fixer": "^3.3"
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-mbstring": "*",
        "symfony/polyfill-php56": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php73": "*"
    }
}

I know it's a weird configuration, but I'm just curious about the reasoning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove a requirement from the application there is nothing much we can do to help you, I mean these are in there for the reason that they are required. If you share how you installed the app like Julien asked we might be able to help, but otherwise not sure what we can do here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SpacePossum I already shared my composer.json. That should be enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then the check is still required indeed. If you don't mind, please submit a PR to fix that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is the check still required, is it not in the polyfil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the polyfill, we would have to check whether the function exists even with ext-mbstring installed because the function was added in PHP 7.4. But the polyfill has a different behavior because it creates it regardless of the PHP version.

I'm actually not sure about this being a BC break. We can:

  • consider using the polyfill is safe and we don't add the check back: people removing the polyfill do it at their own risk, but it means we rely on the polyfill's specific behavior, which one could considerer a bit risky
  • or we consider the poolyfill's specific behavior a quirk and we need to add the check back because we still support some PHP versions before 7.4
  • or we drop PHP 7.2 and 7.3 support, removing the problem entirely 😁️

I would go with last option but I'm fine with any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extention evolves over time, they add new functionality. we don't version the extension, but we can version the polyfill. i would expect nobody messing up with PHP CS Fixer requirements.
If you have extension in place, but old one (eg for PHP 7.1), then the polyfill will add only missing functionalities.

(drop of PHP 7.2/7.3 support is short term solution, the same concern would reappear later)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So option 1: we keep current situation and don't add the check back?

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

Successfully merging this pull request may close these issues.

When check php-cs-fixer version got error "single_Import_per_statement" has invalid name
6 participants