Erroneous flagging of unused variable

In PHPstorm5 the following code will highlight the first instance of $blnError as "unused" due to being redefined right away, which isn't true since it's inside a conditional

   $blnError = 1;
   foreach($v->original_hash as $hash)
    if (md5_file($v->filename) == $hash) $blnError=0; //If one of our hashes matches, clear errorflag



Attachment(s):
Screen shot 2012-10-16 at 11.44.08 AM.PNG
3 comments
Comment actions Permalink

Hi Kris,

Code fragment is too small to give you any concrete comments.

I do see the same message when only this code is used (actually, both instances are highlighted with the same message):

<?php
class M
{
    public function mmm()
    {
        $blnError = 1;
        foreach ($v->original_hash as $hash) {
            if (md5_file($v->filename) == $hash) {
                $blnError = 0;
            }
        }
    }
}


But if I add some variable usage it becomes "normal" (both instances):

<?php
class M
{
    public function mmm()
    {
        $blnError = 1;
        foreach ($v->original_hash as $hash) {
            if (md5_file($v->filename) == $hash) {
                $blnError = 0;
            }
        }
        echo $blnError;
    }
}


If you expand error message (Shift+F1 -- sorry, I'm on Windows and have no clue how to enter that Mac-specific symbol), you will see more correct description.

Based on all of this I think that error summary has incorrect wording, but the error itself may be correct.

0
Comment actions Permalink

Ah - yeah, I had put a die() statement below that code for troubleshooting and that looks like what's going on. The message itself is weird because it's erroring on one of two different conditions and it's "covering all bases". Once I removed by debug and let the program continue where the variable was evaluated, then both highlightings cleared.

0
Comment actions Permalink

You can file new ticket to the Issue Tracker asking developers to review error message summary (it sounds weird/wrong for me as well). Lets see what they say.

0

Please sign in to leave a comment.