Php-cs-fixer: PHP 7.4 features invalidating PHP 7.2 code

Created on 30 Aug 2019  路  12Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

By merging #4380 PHP 7.4 functionality seems to have entered the realm of existing rules which are applied to existing projects. If I understand the code changes correctly there should be a check whether the function exists but for some reason that is not respected. I created a small test case to verify this.

We're running on Docker PHP 7.2 environments so nothing too fancy there.

Are we misconfiguring our tools somewhere or should this be fixed on the CS Fixer side?

Cheers,
L

PHP version: 7.2.19
PHP CS Fixer version: PHP CS Fixer 2.15.2 Europe Round by Fabien Potencier and Dariusz Ruminski (c9d30fd)

Command used;

./php-cs-fixer fix --config=.php_cs test.php

Configuration used;

<?php

return PhpCsFixer\Config::create()->setRules([
    'mb_str_functions' => true,
])->setLineEnding("\n")->setRiskyAllowed(true);

Before running PHP CS Fixer (no changes);

<?php

var_dump(function_exists('mb_str_split'));
// bool(false)

str_split('splitting the string');

With unexpected changes applied when running PHP CS Fixer;

<?php

var_dump(function_exists('mb_str_split'));
// bool(false)

mb_str_split('splitting the string');
// Fatal error: Uncaught Error: Call to undefined function mb_str_split() in /src/test.php on line 5

With the changes you expected instead;

<?php

var_dump(function_exists('mb_str_split'));
// bool(false)

str_split('splitting the string');

Most helpful comment

@LarsGrevelink , released

All 12 comments

Might be good to know that we're retrieving it via;

$ curl -L https://cs.symfony.com/download/php-cs-fixer-v2.phar -o php-cs-fixer

Came here to report the same issue, thanks for opening @LarsGrevelink :-)

PHP version: 7.3.6
PHP CS Fixer version: v2.15.1 (installed with composer)

looks like we need to revert #4380 , thanks for the report

@keradus It was still scratching my head since the code was very solid which was added. Unfortunately, a dependency used by the project adds a polyfill. This is why for the application the function always seems to exist even though it isn't.

Dependency: symfony/console which requires symfony/polyfill-mbstring

Code which causes the eventual issue;
https://github.com/symfony/polyfill-mbstring/blob/b42a2f66e8f1b15ccf25652c3424265923eb4f17/bootstrap.php#L60-L62

Since symfony/console is used as the base application for PHP CS Fixer I think this has to be discussed internally how you want to proceed with this issue. If you decide on the way to go, I'd love to help out in addressing this problem.

exactly what i just wrote here: https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4380/files#r319718704

for now, i will revert as-is, recreate the original PR and we will continue on discussion how to bring this change. most probably, configuration option for the fixer, i believe.

Closing due to merge of #4533
I will release it today

Great, thanks! Keep us posted of any developments and where we can help out!

Thanks!

If you would be willing to help, best place would be to help with reviews! we have quite a few opened, but not that much capacity to deal with all of them as fast as we would want to!

@LarsGrevelink , released

@keradus Thanks! When do you think the latest version is also fetchable through the Symfony URLs as well? Just now only 2.15.2 was available there.

I will see if I can find some time to start reviewing some code in the upcoming days. 馃槃

@LarsGrevelink
our automated page regeneration triggered by deployment ( ref https://travis-ci.org/FriendsOfPHP/PHP-CS-Fixer/jobs/579168739#L580 ) didn't done the trick.
looks to be related to Travis CI Status : Partial System Outage (ref https://www.traviscistatus.com/ )

page is autogenerated nightly, so it should go back to normal

also, php php-cs-fixer self-update should do the trick, as it uses GitHub releases

ker@dus:/tmp 位 php php-cs-fixer --version
PHP CS Fixer 2.15.2 Europe Round by Fabien Potencier and Dariusz Ruminski (c9d30fd)
ker@dus:/tmp 位 php php-cs-fixer self-update
php-cs-fixer updated (v2.15.3)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

OskarStark picture OskarStark  路  3Comments

vitek-rostislav picture vitek-rostislav  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

Bilge picture Bilge  路  3Comments

amitbisht511 picture amitbisht511  路  3Comments