This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 168052 - Small problems with hints ("Variable does not seem to be used in its scope")
Summary: Small problems with hints ("Variable does not seem to be used in its scope")
Status: RESOLVED DUPLICATE of bug 170541
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Tomasz Slota
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-02 16:14 UTC by graste
Modified: 2009-08-18 14:25 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description graste 2009-07-02 16:14:10 UTC
Hi,

there are multiple small problems with the scope-hints in the PHP editor:

1. $first is marked as "Variable does not seem to be used in its scope":

$first = $keys[0];
$foo = $this->bar[$first]->getBaz();


2. $actual is marked as "Variable does not seem to be used in its scope":
$actual = $this->getParsedSegmentsFromFile('BROKEN');
$this->assertTrue($actual[0]['title'] == '');


3. $conn is marked as "Variable does not seem to be used in its scope":
try
{
  $conn = ...;
}
catch (Exception $e)
{
  $conn = ...;
}

or:

if ($someConstraint)
{
   $var = 'foo';
}
else
{
   $var = 'bar'
}

While I wouldn't write code like above, I'm spotting the above pattern very often. Netbeans marks these variables as 
"not used", which is wrong, as they are perfectly valid and always defined after passing the try-catch- or if-then-else-
block. Perhaps the hint message should be changed to something more proper or not displayed as all.




I'm using an up2date Netbeans dev nightly build:

Product Version: NetBeans IDE Dev (Build 2009-04-30_14-26-24 )
Java: 1.6.0_05; Java HotSpot(TM) Client VM 10.0-b19
System: Windows Vista version 6.0 running on x86; Cp1252; de_DE (nb)
Comment 1 grantovich 2009-07-28 19:02:14 UTC
I'm seeing #3 quite often myself, dealing with a large pre-existing code base. There is a second warning triggered in 
patterns like these:

$test = true;
if ($test) {
    $out = 'true!';
} else {
    $out = 'false!';
}
echo $out;

The first two usages of $out are marked "Variable does not seem to be used in its scope" (which is silly, since the if 
statement does not introduce a new scope), and the third usage is marked "Variable might not have been initialized". 
Of course it may be very difficult to make sure the latter warning never appears spuriously, since you have to account 
for all the possible code branches you could travel through to arrive at the current line (imagine if the "else" block 
was a couple hundred lines of nested loops, switches, breaks, returns, and recursive function calls).
Comment 2 rmatous 2009-08-18 14:25:24 UTC
experimental hint

*** This issue has been marked as a duplicate of 170541 ***