[ phpeclipse-Bugs-1426436 ] "The local variable x may not have been initialized" but was

"SourceForge.net" <[email protected]> Fri, 11 May 2007 14:46:16 -0700
Newsgroups gmane.comp.ide.eclipse.phpeclipse.devel
Message-ID <[email protected]>
Bugs item #1426436, was opened at 2006-02-07 12:45
Message generated for change (Comment added) made by emann
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=484801&aid=1426436&group_id=57621

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: PHP Editor
>Group: 1.1.9.CVS-20060920
Status: Open
Resolution: None
Priority: 3
Private: No
Submitted By: Steve Magruder (smagruder)
Assigned to: Nobody/Anonymous (nobody)
Summary: "The local variable x may not have been initialized" but was

Initial Comment:
Using PHPEclipse 1.1.8-cvs-20060129 with Eclipse 3.1.2,
I am seeing variables with red lines under them, and
when I hover over them with the cursor, the error
message reads "The local variable x may not have been
initialized".

However, in these cases, the local variable was indeed
initialized in a php file included at the beginning of
the function ("include filename.php;").  I've been
using Zend Studio 3.0.2 for some time, and it never
complained about these variables not being initialized.

(Note: I am trying to switch to PHPEclipse from Zend
Studio, but I have to iron out issues first)

----------------------------------------------------------------------

>Comment By: Edward Mann (emann)
Date: 2007-05-11 16:46

Message:
Logged In: YES 
user_id=430467
Originator: NO

I tried this with the CVS version of PHPEclipse and could not get it to
show an error. My sample was

Manager.php with $name= "Manager";
Then i had Employee.php that include_once ('Manager.php');
print($name);

No red underscore, and it worked fine. If i mouse over the variable it
will show me a box with 

global variable - [Employee.php] -
global variable - [Manager.php] - 

I still don't think this is right, because if i change the
$name="Manager"; to $name2="Manager"; I don't get an error.


----------------------------------------------------------------------

Comment By: Steve Magruder (smagruder)
Date: 2006-02-08 17:25

Message:
Logged In: YES 
user_id=479830

Oh, I realize I could disable the warning, but I'm afraid I
would end up missing warnings I need to see.  :)

At any rate, I can be patient for a fix for this, compared
to other enhancements I would like to see implemented sooner
(and I noted them in your forum).

Thanks!

----------------------------------------------------------------------

Comment By: Bananeweizen (bananeweizen)
Date: 2006-02-08 16:47

Message:
Logged In: YES 
user_id=440739

I meant the Eclipse parser. We are not (yet) perfect. :)
I currently also work on removing the same warning for all
function arguments, which are given by reference instead of
by value (e.g. function(&arg) ).

And it's not your only choice. As mentioned, you can
completely disable that warning in the preferences.

----------------------------------------------------------------------

Comment By: Steve Magruder (smagruder)
Date: 2006-02-08 16:32

Message:
Logged In: YES 
user_id=479830

Do you mean the PHP or the Eclipse parser?  Because I've
found that in PHP 4.4.x, a local variable can indeed be
declared in an included file.  I have production code
running fine under that premise.

Regarding making the warning go away, your advice appears
sound, although I would certainly prefer not to place an
assignment before includes in all the places I will need to.
 But alas, if that's my only choice, oh well.

Thanks!



----------------------------------------------------------------------

Comment By: Bananeweizen (bananeweizen)
Date: 2006-02-08 01:37

Message:
Logged In: YES 
user_id=440739

The parser does not recognize that the global declaration in
the included file becomes a local variable declaration, when
the file is included in a function (instead of being
included in the global context).
I'm not sure if we can easily fix that. But in the mean time
you can do the following to make the warning go away:
* Configure PHPeclipse or the project to ignore
uninitialized variables (not recommended).
* Put an assignment to that variable just before the include
statement, like

function test() {
$var=null;
include('otherfile.php');
...
}

----------------------------------------------------------------------

Comment By: Steve Magruder (smagruder)
Date: 2006-02-07 19:44

Message:
Logged In: YES 
user_id=479830

Also, I'm running Eclipse/PHPEclipse under Windows 2000. 
Could that possibly make a difference?

----------------------------------------------------------------------

Comment By: Steve Magruder (smagruder)
Date: 2006-02-07 15:48

Message:
Logged In: YES 
user_id=479830

OK, I updated to 1.1.8-cvs-20060207 and set the includes (as
recommended), and that didn't make the warning go away.  And
yes, it was a warning, not an error.

There couldn't have been an error in the same location, as
this code has been run in production for a long time without
problems, and Zend Studio shows no error/warning in those areas.

I already provided the "real" warning message.

----------------------------------------------------------------------

Comment By: Bananeweizen (bananeweizen)
Date: 2006-02-07 15:32

Message:
Logged In: YES 
user_id=440739

(Possibly) uninitialized variables are only shown as a
warning, not as an error, so I think there are two alternatives:
* Either you have configured the PHPeclipse preferences (or
the project settings) to show uninitialized variables as error
* or there is another error at the same position. Please
look in the problems view if there is another error message
for the same place.

So either reconfigure your project to only show warnings, or
look for the real error message, please.

----------------------------------------------------------------------

Comment By: tmose (tmose)
Date: 2006-02-07 15:07

Message:
Logged In: YES 
user_id=1409310

You may need to include your include directory in the
projects properties section.  right click on the project
name in the navigator, choose properties, and then PHP
Project Settings.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=484801&aid=1426436&group_id=57621

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/