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 249508 - In a function, foreach with list($a) warns about uninitialized $a
Summary: In a function, foreach with list($a) warns about uninitialized $a
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: Dev
Hardware: All All
: P4 normal with 1 vote (vote)
Assignee: junichi11
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-23 23:59 UTC by requinix
Modified: 2017-05-26 01:52 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 requinix 2014-12-23 23:59:43 UTC
<?php
function foo() {
  foreach ([] as list($a, $b, $c)) {
    $a; $b; $c; // Variable $a/$b/$c seems to be uninitialized
  }
}
?>

<?php
foreach ([] as list($a, $b, $c)) {
  $a; $b; $c; // no warnings
}
?>

Only happens when inside a function or class method. No difference with a containing namespace and/or declare (in either statement or block form).
Comment 1 Megas 2017-03-19 16:08:05 UTC
The problem still exists.
Any progress in fixing for last 2 years?
Comment 2 junichi11 2017-05-22 04:15:29 UTC
(In reply to Megas from comment #1)
> The problem still exists.
> Any progress in fixing for last 2 years?

Is the expected result the following?

<?php
function foo() {
  foreach ([] as list($a, $b, $c)) {
    $a; $b; $c; // Variable $a/$b/$c seems to be "unused" in its scope
  }
}

If no, could you provide some examples with expected and actual results?

Thanks.
Comment 3 requinix 2017-05-22 07:03:32 UTC
I don't remember this code showing an unused warning back then so that (or my settings) may have changed since.

The expected behavior is that the same code inside and outside of a function should be analyzed the same way with respect to the uninitialized warning. So yes: it should show only the unused warning in both cases.

Here's a small update to the repro code:

// good
foreach ([] as list($a, $b, $c)) {
  echo $a, $b, $c; // expected: no warnings, actual: no warnings
}

// bad
function foo() {
  foreach ([] as list($a, $b, $c)) {
    echo $a, $b, $c; // expected: no warnings, actual: $a/$b/$c uninitialized
  }
}
Comment 4 junichi11 2017-05-23 04:27:41 UTC
(In reply to requinix from comment #3)
> I don't remember this code showing an unused warning back then so that (or
> my settings) may have changed since.
> 
> The expected behavior is that the same code inside and outside of a function
> should be analyzed the same way with respect to the uninitialized warning.
> So yes: it should show only the unused warning in both cases.
> 
> Here's a small update to the repro code:
> 
> // good
> foreach ([] as list($a, $b, $c)) {
>   echo $a, $b, $c; // expected: no warnings, actual: no warnings
> }
> 
> // bad
> function foo() {
>   foreach ([] as list($a, $b, $c)) {
>     echo $a, $b, $c; // expected: no warnings, actual: $a/$b/$c uninitialized
>   }
> }

I see. I'll try to fix it later.

Thanks!
Comment 5 junichi11 2017-05-25 01:17:51 UTC
Fixed.

http://hg.netbeans.org/web-main/rev/fb1bd20ec6ee

Thanks.
Comment 6 Quality Engineering 2017-05-26 01:52:13 UTC
Integrated into 'main-silver', will be available in build *201705260001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/fb1bd20ec6ee
User: Junichi Yamamoto <junichi11@netbeans.org>
Log: #249508 - In a function, foreach with list($a) warns about uninitialized $a