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.
Steps to reproduce: <?php $str = 'String'; preg_match('/pattern/', $string, $matches); ?> Result: Hint "Variable $matches seems to be uninitialized" shown on $matches Expected result: No hint
It will not be so easy to fix, because I really can't know if that parameter is used by reference or not. I would have to know the declaration of that function which is currently invoked :) Parse its parameters and check if my currently processed variable is used by reference from the declaration.
Maybe you could at least fix it for built-in php functions? I have no idea of how netbeans works under the hood, nor do I plan to, but when invoking code completion for by example preg_match, netbeans shows me that $matches is passed by reference. This means that netbeans is aware of this, somewhere. Is it not possible to somehow link this information with the hint?
Yes, NetBeans knows the declaration of functions, it's all in the index (native PHP functions are in signature files, which are indexed as well). But I'm afraid of performance...I think that this case should be fixed in next release to avoid performance problems...fix this today, few days before code freeze, is really dangerous.
Good point. I was not aware of the coming code freeze (very busy with other things than netbeans lately). I'll add my private e-mail as cc to this issue so I wont forget about it and will test it when it's fixed.
I have prepared patch which solves it...but counting of hints takes about 20s in a file with almost 30 000 lines...maybe I'll prepare an option to switch reference checking off.
(In reply to comment #5) > I have prepared patch which solves it...but counting of hints takes about 20s > in a file with almost 30 000 lines...maybe I'll prepare an option to switch > reference checking off. Thanks! :) Is the patch available yet? Imho 20s in a 30 000 line file is no problem. If someone is working on a file of 30 000 lines, maybe that person should concider some drastic refactoring or finding another job :p (no offence to anyone ;))
I can agree with you, but people are weird and we have to deal with em :) No, it's not a public patch, I'll apply it after code freeze...into next version.
True that. Let me know when it's integrated into a nightly :)
Fixed in web-main: http://hg.netbeans.org/web-main/rev/75eb1b4d9828 (option to enable this feature is in Tools -> Options -> Editor -> Hints -> PHP -> Uninitialized Variabled)
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/75eb1b4d9828 User: Ondrej Brejla <obrejla@netbeans.org> Log: #204589 - "Variable seems to be uninitialized" hint shown when initializing variable by reference
*** Bug 242520 has been marked as a duplicate of this bug. ***
This still happens NetBeans 8.2 / PHP 5.6 Here's a sample code: class Example { public static function getNameSlug($classname, $id, &$slug) { $slug = 'something'; return 'another'; } } $name = self::getNameSlug($classname, $id, $s); Shows "Variable $s seems to be uninitialized".
Already in NetBeans 11 and this still isn't fixed... :(