102.194 - Use of list() should not require initialization

I am considering filing this as a bug, but I'd like some feedback. Why am I being told to initialize the variables in this screen shot?

list1.JPG

Using this contruct, there is no need. The use of these variables would never occur if they were not assigned by the list() command:

while($rSQL && (bool)
   list($i75StepsMachinesID, $i75StepsModsOptionsID, $sHeavyLight) = mysql_fetch_array($rSQL))

//if this doesn't happen, they aren't used anyway.
   self::$aMods[$i75StepsMachinesID][$sHeavyLight] = $i75StepsModsOptionsID;

I've gone round and round with other IDE's about this as well. We use this a lot. I'll probably have to write intializion entries for about 2000 variables to satisfy PHPStorm on this issue, and it's redundant.

9 comments
Comment actions Permalink

In fact, it's the kind of thing that has made us drop other IDE's in the past. The IDE should help us write better code, not force us to follow some blanket technical guideline, even when it's useless.

0
Comment actions Permalink

Hello Keith,

It looks like a bug in your code, but the problem not related to initialization using list()

Cosider the following loop:

while(expr() && list($a,$b) = foo()){
    echo $a;
    echo $b;
}

'&&' is a kind of short circuit operator and if expr() is 'true', the right operand will not be evaluated.
And it might be Undefined variable.
Use '&' in your case.

0
Comment actions Permalink

Ok, but that is NOT what I am doing. There is no bug in my code. We use this construct all the time. In this example:

while($rSQL && (bool)
   list($i75StepsMachinesID, $i75StepsModsOptionsID, $sHeavyLight) = mysql_fetch_array($rSQL))

//if this doesn't happen, they aren't used anyway.
   self::$aMods[$i75StepsMachinesID][$sHeavyLight] = $i75StepsModsOptionsID;

$i75StepsMachinesID can only be used IF IT IS ASSIGNED using the list. If $rSQL is false, then it will never be used.

0
Comment actions Permalink

Will liteally will have to do this for 2000 variables:

$i75StepsMachinesID           = null;

$i75StepsModsOptionsID       = null;

$sHeavyLight                         = null;


while($rSQL && (bool)
   list($i75StepsMachinesID, $i75StepsModsOptionsID, $sHeavyLight) = mysql_fetch_array($rSQL))

//if this doesn't happen, they aren't used anyway.
   self::$aMods[$i75StepsMachinesID][$sHeavyLight] = $i75StepsModsOptionsID;

0
Comment actions Permalink

Keith,

Will liteally will have to do this for 2000 variables:

$i75StepsMachinesID           = null;

$i75StepsModsOptionsID       = null;

$sHeavyLight                         = null


No. Try to use '&' instead of '&&' in this condition.

while($rSQL && (bool)

   list($i75StepsMachinesID, $i75StepsModsOptionsID, $sHeavyLight) = mysql_fetch_array($rSQL))

//if this doesn't happen, they aren't used anyway.
   self::$aMods[$i75StepsMachinesID][$sHeavyLight] = $i75StepsModsOptionsID;

0
Comment actions Permalink

Ok, I realised that it is a bug on our side. Please report a bug request.

0
Comment actions Permalink

http://youtrack.jetbrains.net/issue/WI-4824

FYI, this makes this version unusable to us (that's 2 EAP's in a row that we could not use.) Too much cleanup to make it accurate, or we'd have to disable this Inspector setting, which we rely on and works in 102.18

0
Comment actions Permalink

102.206 fixed the problem. Thanks for the quick response!!!!

0
Comment actions Permalink

The issue page for this reports it was fixed in 102.206, but it wasn't and it's not fixed in 103.8 either.

http://youtrack.jetbrains.net/issue/WI-4824?projectKey=WI&query=by%3A+me#content-tab=0

I'm going to retract this statement. It's a flaw in our coding.

I was treating this:

if($rSQL) list($a, $b) = mysql_fetch_array($rSQL);

like this:

while(list($a, $b) = mysql_fetch_array($rSQL)){

echo $a;

echo $b;

}

Wow. We've got a lot of cleanup to do.

Message was edited by: Keith Davis

0

Please sign in to leave a comment.