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 220993 - Inappropriate "variable is unused" warning for inherited class
Summary: Inappropriate "variable is unused" warning for inherited class
Status: RESOLVED WORKSFORME
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-29 08:50 UTC by davidkarlin
Modified: 2012-10-29 09:55 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 davidkarlin 2012-10-29 08:50:46 UTC
Consider the following code:

class parentClass {
    public $id;
    /**
     * Save this object, allowing child classes to use custom behaviour
     */
    protected function save($database) {
        saveToDatabase($this, $database);
    }
}

class childClass extends parentClass {
    /**
     * This class has a custom save which sends it to a file, not the database
     */
    protected function save($database) {
        // Overrides the parent
        saveToFile($this, 'childclass_' . $this->id);
    }
}

The inherited save function will display a warning that the variable $database is not used. However, there is now nothing that the developer can do to get rid of this warning, because if you get rid of the $database parameter in childClass::save(), PHP will throw you an error saying that your child class is incompatible with the parent.

Ideally, the hinter would figure out that the $database variable is used in the parent definition. If that's not possible, it would be nice to have a @suppresswarning xxx kind of facility so that the developer can produce a clean file.

(In build 201207171143)
Comment 1 Ondrej Brejla 2012-10-29 09:16:07 UTC
Go to: Tools -> Options -> Editor -> Hints -> PHP -> Unused Variables and UNcheck "Check Unused Method/Function Parameters". Nothing else can't be done. That parameter is really NOT used ;)
Comment 2 davidkarlin 2012-10-29 09:52:26 UTC
I really disagree with you.

Of course, I could disable the warning globally. But if I do that, I lose the warnings for everything, including the cases where there are genuine problems of the variable not being used.

This isn't the only case where the hinter is generating warnings that I would like to suppress individually, and a look on StackOverflow etc indicates that I'm by no means the only one who thinks this.

Surely a facility to suppress a particular warning at a particular point in the code should be possible - and would be generally helpful to anyone who has a general policy of zero tolerance for warnings but has individual instances where, for whatever reason, he needs to do something that isn't compliant?
Comment 3 Ondrej Brejla 2012-10-29 09:55:51 UTC
I understand what you mean, but sorry, the hint is right here. We can implement some another functionallity of @SuppressWarning annotations, but that's another issue (especially new feature). You can file a new enhancement for it [1].

Thanks!

[1] http://netbeans.org/bugzilla/enter_bug.cgi?product=php