Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Variable undefined warning for array with short array syntax
Variable undefined warning for array with short array syntax [message #1710537] Wed, 07 October 2015 11:32 Go to next message
Jason Siebert is currently offline Jason SiebertFriend
Messages: 3
Registered: October 2015
Junior Member
Whenever I declare a variable with short array syntax like:
$json ['success'] = 1;

I get a warning that the variable is undefined. If I do it without short array syntax it doesn't cause a warning. I am currently using Mars 4.5.1 with PDT 3.6 and DLTK 5.3.
Re: Variable undefined warning for array with short array syntax [message #1710558 is a reply to message #1710537] Wed, 07 October 2015 14:00 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 207
Registered: March 2013
Senior Member
this error isn't from PDT but from PEX Core-Plugin. Anyway its correct:

$json['success'] = 1; is just array assign. PHP will throw out E_NOTICE, create array and assign 1 to success property,
correct way its:
$json = ['success' => 1];
or
$json = [];
$json['success'] = 1;

You can also disable undefined variable validator in eclipse php preferences (php / validation / semantic analysis)


Re: Variable undefined warning for array with short array syntax [message #1710643 is a reply to message #1710558] Thu, 08 October 2015 07:37 Go to previous messageGo to next message
Jason Siebert is currently offline Jason SiebertFriend
Messages: 3
Registered: October 2015
Junior Member
I was in the thought that the array was defined with that statement. Now I see it actually gets corrected by PHP to be the proper way. Thanks for your insight Dawid!

Edit: Actually without even changing the Semantic Analysis it's working without giving me a warning. I did have a bad build file which I corrected. I also couldn't find the preference "PHP|Validation|Semantic Analysis", all I have listed under "Validation" is "Task Tags"

Any thoughts?

[Updated on: Thu, 08 October 2015 07:45]

Report message to a moderator

Re: Variable undefined warning for array with short array syntax [message #1710689 is a reply to message #1710643] Thu, 08 October 2015 12:17 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 207
Registered: March 2013
Senior Member
Make sure PEX Core-Plugin is installed. Available at http://p2.pdt-extensions.org/ as PDT Extensions.

Re: Variable undefined warning for array with short array syntax [message #1710741 is a reply to message #1710689] Thu, 08 October 2015 19:29 Go to previous message
Jason Siebert is currently offline Jason SiebertFriend
Messages: 3
Registered: October 2015
Junior Member
That's what it was. I had uninstalled it and didn't realize that the extension plugin was the one that gives Eclipse that behaviour. Thanks for the help.

Btw, would you know if there is anything that provides content assist for object oriented php. When I tried to use mysqli->close it gave me the option of ($link), but that's only for procedural php. It should be nothing since the object oriented one takes no arguments.

[Updated on: Thu, 08 October 2015 19:34]

Report message to a moderator

Previous Topic:Configuring PDT to mark undefined methods & functions
Next Topic:Can't setup server with bitnami wordpress in Windows 10
Goto Forum:
  


Current Time: Fri Jan 19 06:03:19 GMT 2018

Powered by FUDForum. Page generated in 0.02636 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software