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 170255 - Hint on unused functions and vars ignores assertions
Summary: Hint on unused functions and vars ignores assertions
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Ondrej Brejla
Depends on:
Reported: 2009-08-12 10:30 UTC by marcusson
Modified: 2012-04-24 12:50 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description marcusson 2009-08-12 10:30:58 UTC
The hint that reports unused functions vars and class members ignores code in assertions.


class FooEnum
    const A = 0;
    const B = 1;
    const C = 2;
    private static $_valid = array(self::A,self::B,self::C);
    private $foo = self::A;
    public function setFoo($value)
        // pre-condition
        assert('in_array($value, self::$_valid); // Invalid input type');
        // more code
        // post-condition
        assert('in_array($this->foo, self::$_valid); // Invalid output type');
    public function getFoo()
        // pre-condition
        assert('in_array($this->foo, self::$_valid); // Invalid output type');
        return $this->foo;

For the above snippet NetBeans will report FooEnum::$_valid as unused. But it is not - and if it is removed (as NetBeans
suggests) all assertions will result in runtime-errors terminating the program.

While unlike Java, assertions are always embraced in quotes in PHP, they are real source code and should be interpreted
that way - just as they are in Java. If NetBeans supports the one it should also work with the other.

Personally I would prefer that NetBeans would be able to honor assertions. At least when it comes to single-quoted
strings in assertions like '$foo' - which is 1:1 standard PHP source-code. I understand that there are more complex
examples where people use variable substitution BUT these are a rarely seen, since it does not comply with common rules
for writing assertions (not in Java and also not in PHP). At least 95% of all assertions will use very basic
expressions. Typical assertions are: type-checking, checking that a value doesn't fall below zero, checking that a value
is not Null or a var has not been previously used.

As an alternative it would be nice to at least be able to persistently turn off this warning in NetBeans for just a
single class member, function or variable.

I suggest setting this issue to a low priority and keeping it on the "todo"-list for a future version.
Comment 1 Filip Zamboj 2010-09-15 12:29:39 UTC
batch reassigning
Comment 2 marcusson 2011-11-18 09:13:02 UTC
Can still be reproduced in Netbeans 7.1