Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » "Variable is never used" in foreach loops
"Variable is never used" in foreach loops [message #1792520] Thu, 19 July 2018 02:00 Go to next message
Yurij Zagrebnoy is currently offline Yurij ZagrebnoyFriend
Messages: 2
Registered: August 2013
Junior Member

I often use PHP foreach to iterate over array keys, like:
foreach ($list_of_keys as $key => $_) {
// ...

This is about 2 times faster on big arrays and doesn't consume additional memory compared to using array_keys()
foreach (array_keys($list_of_keys) as $key) {
// ...

The problem is that each $_ variable produces warning "Variable $_ is never used".

Is there any way to configure PHP Validator to exclude variables with certain names from checking their usage?

BTW Thank you for your great work on PDT!
Re: "Variable is never used" in foreach loops [message #1793466 is a reply to message #1792520] Wed, 08 August 2018 18:03 Go to previous messageGo to next message
Moses Lecce is currently offline Moses LecceFriend
Messages: 1
Registered: July 2009
Junior Member
I am also experiencing this issue, which basically means I have a bunch of warnings that can't really be resolved without implementing less optimized code.

In addition to this, I have code in third party files (that I do not wish to edit and correct) which come up as warnings (is there a way to exclude a file/directory from warnings, I cannot find such a setting).

Another scenario I cannot seem to handle is something where you are using a reference variable:

$this = array();
$this2 =& $this;
$this2[] = "a";

Will tell me that $this2 is never used.
Re: "Variable is never used" in foreach loops [message #1794915 is a reply to message #1793466] Tue, 11 September 2018 05:53 Go to previous message
Vladimir Paramygin is currently offline Vladimir ParamyginFriend
Messages: 1
Registered: September 2018
Junior Member
Yeah, having the same problem. Upgraded to Photon yesterday and now my project is littered with warnings about undefined and unused variables :(
Previous Topic:Generate Constructor ?
Next Topic:Importing Wordpress into Eclipse
Goto Forum:

Current Time: Sun Sep 23 03:22:59 GMT 2018

Powered by FUDForum. Page generated in 0.01616 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top