Opened 7 years ago

Closed 4 years ago

Last modified 3 years ago

#429 closed Bugs (invalid)

"The local variable x may not have been initialized" but was

Reported by: smagruder Owned by: nobody
Priority: 3 Milestone: 1.3.0
Component: PHP Editor Version: 1.2.0-nightly
Keywords: formatter, code style Cc:

Description (last modified by ed_mann)

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)

Attachments (2)

429_sample_a.php (27 bytes) - added by scorphus 5 years ago.
429_sample_b.php (173 bytes) - added by scorphus 5 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 7 years ago by tmose

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.

comment:2 Changed 7 years ago by bananeweizen

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:3 Changed 7 years ago by smagruder

  • Status changed from assigned to closed
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:4 Changed 7 years ago by smagruder

Logged In: YES 
user_id=479830

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

comment:5 Changed 7 years ago by bananeweizen

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:6 Changed 7 years ago by smagruder

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:7 Changed 7 years ago by bananeweizen

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:8 Changed 7 years ago by smagruder

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:9 Changed 6 years ago by emann

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:10 Changed 6 years ago by scorphus

Logged In: YES 
user_id=987242
Originator: NO

This bug is still present. I'm adding sample code that illustrates this bug. There are two files, 1426436_sample_a.php and 1426436_sample_b.php, which includes the former.

PHPeclipse 1.1.9-CVS (current)
Eclipse 3.2.2 Build id: M20070212-1330
Sun Java version 1.5.0_06
File Added: 1426436_sample_a.php

comment:11 Changed 6 years ago by scorphus

Logged In: YES 
user_id=987242
Originator: NO

File Added: 1426436_sample_b.php

comment:12 Changed 6 years ago by scorphus

Logged In: YES 
user_id=987242
Originator: NO

File Added: 1426436_sample_b.php

comment:13 Changed 5 years ago by ed_mann

  • billable set to 0
  • Description modified (diff)
  • Keywords formatter, code style added
  • os_platform set to Linux

Just adding some tags to help group bugs together

comment:14 Changed 5 years ago by ed_mann

  • Milestone set to 1.2.x
  • Version changed from 1.1.9.CVS-20060920 to 1.2.0-nightly

Changed 5 years ago by scorphus

Changed 5 years ago by scorphus

comment:15 Changed 5 years ago by scorphus

I've attached the files. The bug gets shown in line 4 of 429_sample_b.php

comment:16 Changed 5 years ago by ed_mann

  • Milestone changed from 1.2.x to 1.3.x

comment:17 Changed 4 years ago by incastrix

  • Resolution changed from None to invalid
  • Status changed from assigned to closed

too old!

Note: See TracTickets for help on using tickets.