X

An Oracle blog about NetBeans for PHP

Smart Method Parameters Pre-Filling

Hi all, today we would like to introduce you a new feature which will be, we hope, very helpful for you! It makes pre-filling of method/function parameters really smart.

Let's start with an old behaviour. If you had a method with parameters described in PHPDoc, code completion of this function didn't care about that. It suggested you just the names of it's parameters, even though you had your own variables of a valid type declared right before code completion invocation.

It was really annoying. But now, code completion suggests you your valid variables (of desired type), so you don't have to rewrite method calls everytime you use code completion. Isn't that great? I think it is! So now that suggestion looks like this:

And the last thing. If you have your variables named exactly as parameters of suggested function and they are of desired types, you don't have to care about positions of these variables in invocation scope. They are used always, even though some other variables of desired types exist closer your completion invocation.

And, of course, it works for PHP built-in functions as well.

So that's all for today and as usual, please test it and if you find something strange, don't hesitate to file a new issue (product php, component Editor). Thanks.

Join the discussion

Comments ( 16 )
  • guest Wednesday, August 31, 2011

    Great enhancement :)


  • Koen Wednesday, August 31, 2011

    Wow that looks really cool! Can't wait to try it out and see if it really saves you work!


  • Michael Butler Thursday, September 1, 2011

    Yet another thing that vim can't do! Thanks!


  • guest Sunday, September 4, 2011

    I'm not sure that displaying the type in place of the variable name is an improvement.

    I normally give my variables meaningful names so will likely find it frustrating when I see "function($int, $int, $int)". I'll have to look up what each parameter is before I can use it. Which makes auto-complete less useful.


  • guest Sunday, September 4, 2011

    I'm not sure that displaying the type in place of the variable name is an improvement.

    I normally give my variables meaningful names so will likely find it frustrating when I see "function($int, $int, $int)". I'll have to look up what each parameter is before I can use it. Which makes auto-complete less useful.


  • Pieter Tuesday, September 6, 2011

    Sounds like a great timesaver. Good work, thanks!


  • Ondrej Brejla Wednesday, September 7, 2011

    RE: Posted by guest on September 05, 2011 at 01:05 AM CEST

    Don't worry, it can't happen, because every defined variable is used only once. So if you have a function with 3 int parameters and you have an $int variable defined before method invocation, you will just see "function($int, <original>, <original>).


  • guest Sunday, September 11, 2011

    Very Good


  • Zimzat Saturday, September 17, 2011

    Something that concerns me very greatly about this feature is how much information it will be removing from context. For example, let's say I have this scenario:

    /**

    * @param string $status

    * @param integer $reportId

    * @param integer $userId

    */

    protected function _setReportUser($status, $reportId, $userId) {}

    /* Then this code somewhere else */

    $unrelatedString = 'blah blah blah';

    $activeReportId = 1;

    $activeUserId = 2;

    $this->_setReportUser(/* suggestion will be ... */);

    $this->_someOtherAction($unrelatedString, $activeReportId); /* This is what I would be doing with that string */

    Will it suggest ($unrelatedString, $activeReportId, $activeUserId) and not show the original variable names? That original variable name of $status is very critical, as an agreement between the function writer and the function caller, of what internal type of data can be expected.

    Or, maybe it will show ($unrelatedString, $activeUserId, $userId)? Again, that's confusing and very misleading.

    This feature sounds like Netbeans trying to be too smart for its own good, and getting in the way of the programmer and the written definitions. At the very least I hope we'll have the option to completely turn off this behavior.


  • Ondrej Brejla Monday, September 19, 2011

    Hi Zimzat,

    firstly, thanks for your feedback.

    And answers for your questions:

    1) line with $this->_setReportUser will suggest "$unrelatedString, $activeUserId, $activeReportId"

    2) line with $this->_someOtherAction will suggest "$unrelatedString, $activeUserId"

    And if it's not comfortable for you and you would like to have a "classic" behaviour, you can switch this feature off in "Tools->Options->Editor->Code Completion->PHP->Use Smart Parameters Pre-Filling" (this option is new, will be in PHP daily build in one hour I hope)


  • rosswald Friday, September 23, 2011

    This sounds interesting, but as Zimzat pointed out, it could be misleading in some cases. I guess it will have to survive some live testing, and to determine hit-to-miss ratio, to see whether is it actually time-saving or error-inducing.


  • Ondrej Brejla Friday, September 23, 2011

    As I wrote in the last comment, now there is a possibility to disable that feature, so if you will not be satisfied with that, you can switch it off ;)


  • rosswald Friday, September 23, 2011

    Yup, making everything configurable is one of the reasons I use Netbeans :)


  • guest Sunday, September 25, 2011

    Please disable this feature by defaut. IMHO, it is a dangerous feature. Sometimes, it can help a little bit as it was planned. But some other times, it will induce errors! See this code:

    $userId = 0;

    $teacherId = 0;

    $course = getCourse(

    With this feature, NB will display "$userId" as first parameter. So you won't know what was really declared, and it can lead to errors you would never have made with the old behaviour. And it's even more dangerous for first-time users that don't know about this "smart renaming".

    Please don't mangle with the function parameters' names, they are meaningful. Never wondered in a PHP function about the order of $needle and $haystack?


  • mjh_ca Monday, October 24, 2011

    Seems like a very random and not well-thought-out feature. Very hack-ish. Should most definitely NOT be turned on as a default. The code completion should show the parameter type and name -- inferring which variables I want to use from the current scope is just silly and in some cases inviting you to make mistakes that you wouldn't otherwise make.


  • Ondrej Brejla Tuesday, October 25, 2011

    Yes, I rewrote it and now you see original params and their types in CC...and variables are prefilled "after" you apply that CC. So now it's the same like in Java editor.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services