Php-cs-fixer: Add ImplodeCallFixer

Created on 11 Jul 2018  路  5Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

Function implode can be called in 3 ways, one - not documented - which should be fixed:

 <?php
-implode($pieces , '');
+implode("", $pieces );

and two that are correct:

<?php
implode("", $pieces);
implode($pieces);

How should we handle these 2 signatures? I could not find any conclusive reason one is better than the other - should the fixer have an option empty_string with values ensure and remove? If so what would be the default (and why?) and would that default be our default here?

Or maybe one signature is somehow better and should be recommended?

kinfeature request

Most helpful comment

It seems to be symfony standard to use implode('', $pieces) instead of implode($pieces).

All 5 comments

:+1: for fixing to implode("", $pieces); , as it is more explicit and used in same way as the counter part explode

Maybe implode($pieces , '') will be deprecated in 7.4:

https://wiki.php.net/rfc/deprecations_php_7_4

The following are still Work-In-Progress and ideas:

  • Unify parameter order for implode() to match explode()

The implode($pieces , '') case is obvious how to handle - I'm asking how to approach 2 correct, documented usages.

I agree to @SpacePossum, we should fix it to the explicit one implode('', $pieces).
I would not add a configuration option for it, until it is explicitly demanded by someone who wants to use implode($pieces).

It seems to be symfony standard to use implode('', $pieces) instead of implode($pieces).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OskarStark picture OskarStark  路  3Comments

fisharebest picture fisharebest  路  3Comments

UksusoFF picture UksusoFF  路  3Comments

amitbisht511 picture amitbisht511  路  3Comments

aidantwoods picture aidantwoods  路  3Comments