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 204589 - "Variable seems to be uninitialized" hint shown when initializing variable by reference
Summary: "Variable seems to be uninitialized" hint shown when initializing variable by...
Status: REOPENED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Windows 7 x64
: P3 normal with 1 vote (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
: 242520 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-11-02 14:43 UTC by maghiel
Modified: 2019-05-05 02:47 UTC (History)
3 users (show)

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 maghiel 2011-11-02 14:43:16 UTC
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
Comment 1 Ondrej Brejla 2011-11-02 16:57:52 UTC
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.
Comment 2 maghiel 2011-11-02 23:07:28 UTC
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?
Comment 3 Ondrej Brejla 2011-11-03 09:19:42 UTC
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.
Comment 4 maghiel 2011-11-04 15:34:54 UTC
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.
Comment 5 Ondrej Brejla 2011-11-09 16:11:19 UTC
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.
Comment 6 maghiel 2011-11-10 20:01:41 UTC
(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 ;))
Comment 7 Ondrej Brejla 2011-11-11 08:12:33 UTC
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.
Comment 8 maghiel 2011-11-11 15:05:16 UTC
True that. 
Let me know when it's integrated into a nightly :)
Comment 9 Ondrej Brejla 2012-01-12 14:21:13 UTC
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)
Comment 10 Quality Engineering 2012-01-13 21:52:57 UTC
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
Comment 11 dharkness 2014-04-17 19:23:41 UTC
*** Bug 242520 has been marked as a duplicate of this bug. ***
Comment 12 beany 2017-01-28 12:46:46 UTC
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".
Comment 13 beany 2019-05-05 02:47:20 UTC
Already in NetBeans 11 and this still isn't fixed... :(