Include file gives undefined variable warning

General discussion on Zend Studio

Re: Include file gives undefined variable warning

Postby albertsj1 on Fri Aug 21, 2009 4:53 pm

totalsupport wrote:Configuration variables are usually defined as constants. But this is an entirely different discussion. Just saying that, in the long run, you'll be happy when you've tried to avoid these kind of constructions... ;)

Anyway, fortunately you can completly customize the warnings that the analyzer gives you.

Go to Preferences -> PHP -> Code Analyzer.
You'll find your warning under the 'Security' section (just saying, just saying,... ;)): "Use of global variable before definition".
Change the value on the right from "warning" to "ignore".


Excellent. That was exactly what I was looking for. Thank you very much.

John
albertsj1
 
Posts: 5
Joined: Fri Aug 21, 2009 3:04 pm

Re: Include file gives undefined variable warning

Postby totalsupport on Fri Aug 21, 2009 4:59 pm

You're welcome!
But for the love of god, stay away from anything called 'global' please.

/edit:
seopaul, please look up the principles and best practices behind scopes. You're actually solving a cosmetical IDE problem (CA-warnings) that has nothing to do with how an application runs, by inserting actual code... using globals? This is wrong three times over.
(Dont want to hijack this thread, this is my last post here about this subject, PM me if you'd like to continue this discussion)
totalsupport
 
Posts: 123
Joined: Thu Aug 20, 2009 2:38 pm

Re: Include file gives undefined variable warning

Postby seopaul on Fri Aug 21, 2009 5:40 pm

Bram,

I wont have people talk to me in that tone, in the physical or digital world it's insulting and condescending to assume without asking further questions what people do and do not need to research, you should of read abit more of what i said before trying to "educate" me, mainly the part where i say "i moved away from using globals awhile ago so abit rusty debuging those errors".

for future reference, programming tips to other lead programmers/CTO's are best done over PM when the advice is not asking for.
seopaul
 
Posts: 41
Joined: Wed Jun 10, 2009 1:37 pm

Re: Include file gives undefined variable warning

Postby gryphonws on Fri Aug 21, 2009 8:07 pm

@albertsj1
Yes, it seems like we have the exact same issue. I'm seeing 1000's of warnings as well in my problems tab because I'm working on an open source project which I haven't created myself. Needless to say, it slows ZS down and fixing those warnings by altering hundreds of php files just isn't an option. I've narrowed it down to show only "Errors/Warnings on Selection" instead of "Errors/Warnings on Project" (Problems tab > View Options)..which is already a nice improvement.

Go to Preferences -> PHP -> Code Analyzer.
You'll find your warning under the 'Security' section (just saying, just saying,... ;)): "Use of global variable before definition".
Change the value on the right from "warning" to "ignore".


Thanks for that, I'm going to give that a try!

The ideal solutions for me would be that ZS somehow opens included files internally so it's able to see that it shouldn't show those undefined variable warnings. Too bad that that's not an option. Disabling warnings all together means that it doesn't show those warnings when I think it should.. Guess I'll have to live with it :)

Thanks everyone for the coding tips. When I start with a blank project, I'll enable the warnings and make sure to use the coding style as suggested so it doesn't show the warnings. When I open php scripts that I haven't created myself, I'll just disable the warnings in the Security section to avoid the 1000's of warnings :)

Thanks again,
John
gryphonws
 
Posts: 8
Joined: Sat Aug 15, 2009 1:40 pm

Re: Include file gives undefined variable warning

Postby gryphonws on Fri Aug 21, 2009 8:12 pm

totalsupport wrote:You're welcome!
But for the love of god, stay away from anything called 'global' please.


Actually defining variables as global such as in functions is something I've never done because I know what it can lead to. However, initializing variables like $admin_email = 'john@doe.com'; inside a config file for example which is going to be included in other files is something I've done many times and I've never ran into any kind of problem with it. But all that will be gone soon, I've picked up a book on OOP ;)
gryphonws
 
Posts: 8
Joined: Sat Aug 15, 2009 1:40 pm

Re: Include file gives undefined variable warning

Postby seopaul on Fri Aug 21, 2009 9:05 pm

Its a good point you made, ZS should know its a var in a include maybe its worth rasing a bug?
seopaul
 
Posts: 41
Joined: Wed Jun 10, 2009 1:37 pm

Re: Include file gives undefined variable warning

Postby gryphonws on Sat Aug 22, 2009 12:08 am

seopaul wrote:Its a good point you made, ZS should know its a var in a include maybe its worth rasing a bug?


I would, but I don't think it's a bug, but just something that isn't being supported by ZS?

I have a ZS 5 license and used it for quite a while, but only to edit single script files, so I never used the projects feature the way I do now with my ZS 7 demo. The first day I used ZS 7, one of the first things I used was the projects feature. I created a new project for an open source dating script and immediately noticed the 1000's of warnings. I didn't change any of the default settings for ZS 7, so if it really was a bug, I'm sure the developers would have noticed it themselves. I noticed it within 20 minutes of using ZS 7 :)

Because of this, I somehow think that I'm not using ZS the way I should..as if I'm doing something wrong and missing some kind of setting or something. Especially since I haven't seen any other posts about this on the forum, or anywhere else.
gryphonws
 
Posts: 8
Joined: Sat Aug 15, 2009 1:40 pm

Re: Include file gives undefined variable warning

Postby lepapounet on Sun Aug 23, 2009 9:55 pm

Hello,
before using ZS7,I am using eclips ganymede with pdt extension and with this I don't have these message
I have compared the 'preference' and aply the same parameter but the result is differnt between these version
I hope than zend adjust these parameter

regards
lepapounet
 
Posts: 3
Joined: Sun Aug 23, 2009 9:45 pm

Re: Include file gives undefined variable warning

Postby michanagel on Sun Jan 31, 2010 11:18 pm

Hey,

I just purchased Zend Studio 7.1 and I have the exact same issue described in this thread.

Variables defined in included files are not being recognized by ZS...

Is there a fix for this in the making ?

Since this problem has been around for a while I am wondering why this has not been addressed yet...

Thanx.

- Mike
michanagel
 
Posts: 13
Joined: Sun Jan 31, 2010 11:15 pm

Re: Include file gives undefined variable warning

Postby lepapounet on Thu Mar 11, 2010 11:27 am

Hi
I Be afraid
any news, any comment, new version and always same problem (BUG????)

some body find the solution ?????

thanks
lepapounet
 
Posts: 3
Joined: Sun Aug 23, 2009 9:45 pm

PreviousNext

Return to Zend Studio

Who is online

Users browsing this forum: No registered users and 4 guests

cron