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 170205 - Variable renaming not working in assertion
Summary: Variable renaming not working in assertion
Status: REOPENED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-11 14:37 UTC by marcusson
Modified: 2016-09-22 03:16 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description marcusson 2009-08-11 14:37:31 UTC
Globally renaming a variable works well - except for assertion.

See this example:

/**
 * set name
 * @param string $name
 */
public function setName($name)
{
    assert('is_string($name);');
    $this->name = $name;
}

Renaming variable $name renames every occurrence except for the variable reference inside the assertion.
This causes all assertions to fail, which use this name.
Comment 1 rmatous 2009-08-11 15:11:36 UTC
Single quoted strings - variables and escape sequences for special characters will not be expanded 
&& netbeans code doesn't care about its content

workaround:
assert(is_string($name)); 
Comment 2 marcusson 2009-08-11 17:00:38 UTC
This workaround is _not_ an option.

There is a reason for these quotes in assertions. It is part of the language specification.

leaving off the quotes will:
1) drop the assertion message and render it totally useless, because you are unable to determine the reason for a failed
assertion
2) prevent live applications in a production-environment from being able to turn off assertions, resulting in (possibly
extreme) performance issues

Assertions are an important part of the design-by-contract programming paradigm and cannot be avoided.
You will find such checks in _all_ functions for just about _every_ var which is ever defined.

Assertion mark pre-condition, invariant conditions, post-condition and even the begin-of-life point for any defined
variable, like this:
assert('!isset($foo); // Cannot redeclare var $foo');
$foo = null;

Actually you will experience that several functions have more assertions than lines of code.
As an example: I got 1800 assertions in 100 files.

I suggest to re-open this issue.
Comment 3 Tomas Mysik 2009-08-12 09:52:38 UTC
We will try to look at it but this issue has no easy solution.
Comment 4 marcusson 2009-08-12 10:39:20 UTC
I do understand that this is complicated.

Perhaps it might help to look at it that way:

assert('!isset($foo); // Cannot redeclare var $foo');
assert('<expression1>; <expression2>');

is just the same as the Java-style code:

assert !isset($foo) : Cannot redeclare var $foo;
assert <expression1> : <expression2>;

(Note that this is not valid PHP-code)

Most (if not all) annotations will be very straight-forward, easy expressions and composed in that way.
Be careful with double-quotes though. Assertions using expressions in double-quotes are rarely seen, uncommon, more
complex situations. I believe it would be okay to ignore these.
Comment 5 marcusson 2009-08-12 10:47:41 UTC
As a side-note: I believe that this should be low priority. If find out that this is too complicated for now, you may
want to reduce the priority and just keep it for some future release.

I've added another issue 170255 which is related to this one. You may decide to reduce the priority of both and fix them
some time later.
Comment 6 Filip Zamboj 2010-09-15 12:29:38 UTC
batch reassigning
Comment 7 marcusson 2011-10-14 10:19:18 UTC
Still not fixed in NB7.1.
Comment 8 amobilia 2016-09-22 03:16:12 UTC
Reproductible in 8.2rc / Dev 201609210002