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.
In addition to issue #246230, there are two more cases where I am forced to declare a variable to receive a value that I don't intend to use. I would like NetBeans not to flag these as a warning. While they do have workarounds to avoid the hint, it's not acceptable to complicate the code to satisfy the IDE. 1. Iterating over the keys of an array. // don't need $value foreach ($array as $key => $value) { echo $key . PHP_EOL; } Workaround: Use array_keys() to copy the keys to a new array of values. foreach (array_keys($array) as $key) { echo $key . PHP_EOL; } 2. Ignoring some values extracted using list(). // don't need $id list($id, $author, $title) = explode(',', '123,Charles Lutwidge Dodgson,Alice in Wonderland'); echo "$author is the author of $title\n"; Workaround: Assign the result of explode() to a temporary variable and extract only the values you need. $info = explode(...); $author = $info[1]; $title = $info[2]; echo "$author is the author of $title\n";
Makes sense, thanks.
The first case is especially tricky when iterating over object properties, since foreach (array_keys($object) as $key) { echo $key . PHP_EOL; } doesn't work (the workaround here is even more bloated), while foreach ($object as $key => $value) { echo $key . PHP_EOL; } is fine.
Indeed, but I don't think it matters for the fix. Not using the $value in a foreach should never produce a warning IMHO.