PHP Code Style - list() / []

Is there a code style setting for [] when used as list() (or even for list())?

0
6 comments

I just started using the short syntax for list() ([]), and PS forces the use in foreach to be like this, how awful!

 

0

By the chance, do you have any non-default settings in "Code Style > PHP > Wrapping and braces"? (f.e. in "For()/Foreach() statements" section)

Would it be possible to provide a full example that we could try to reformat?

0

Wow, that was a terrible post. What I meant to say is the options are these (using the settings you indicate), all which suck for us:

foreach($aCase5SkeysDates as [$iCase5Skey, $sTreatmentDate]){
foreach(
$aCase5SkeysDates as
[$iCase5Skey,
$sTreatmentDate]){
foreach(
$aCase5SkeysDates as
[$iCase5Skey,
$sTreatmentDate]
){
foreach(
$aCase5SkeysDates
as
[
$iCase5Skey,
$sTreatmentDate
]
)
{

But I see no way for us to get this:

foreach(
$aCase5SkeysDates as
[
$iCase5Skey,
$sTreatmentDate
]
){

However, if we use the long format for list(), this works:

foreach(
$aCase5SkeysDates as
list(
$iCase5Skey,
$sTreatmentDate
)){

But we are moving away from that to [].

0

Currently, there's no way to configure that.

list() obeys the Function/constructor call wrapping setting, and using [] like this is not even considered an array initializer.

Not sure if there's a way for PhpStorm to tell array destructuring from a plain array, but it's definitely worth taking a look at. Please submit a feature request: https://youtrack.jetbrains.com/newIssue?project=WI

0

"Not sure if there's a way for PhpStorm to tell array destructuring from a plain array"

Actually, that's the problem - it is telling the difference because if this was a plain array, it would format it as I indicated. We want our "structuring and destructuring" of arrays to look the same:

 

$a = 

[

     1,

     2,

     3

];

 

[

     $a,

     $b,

     $c

]  

= $a;

 

I'll submit the request.

 

 

0

Please sign in to leave a comment.