mellis95 Posted April 26, 2010 Share Posted April 26, 2010 I have an application that I designed/coded on LAMP and have been working on/with it for over a year with no issues. However, someone else has downloaded the app from Sourceforge and is trying to run it on WAMP and is getting a lot of errors saying "NOTICE: Undefined constant...." which I believe might be caused because throughout the application, I have been referencing array elements like this: $_SESSION[id] instead of this: $_SESSION['id'] I assume there is a setting in php.ini to allow variables to be referenced without quotes, but I have no idea what it would be, since I have not had a single issue for over a year and quite frankly didn't even realize that I was coding it all wrong. (I think...). Is there a way to make it work without errors on the other users WAMP system for now while I try to add quotes throughout the application? (it may take a while to update that much code!) Thanks in advance. Matt Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 There's no setting for that. PHP used to have notices disabled in it by default. If you put this in your php error_reporting(E_ALL ^ E_NOTICE); It will get rid of the errors. But it's still highly recommended you use quotes around them, since it thinks you are referencing a constant (i.e with define()) but then converts to a string because it is not found, which wastes processing time. Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1048712 Share on other sites More sharing options...
Pikachu2000 Posted April 26, 2010 Share Posted April 26, 2010 More than likely, they tried to modify it and cratered it in the process. Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1048715 Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2010 Share Posted April 26, 2010 As de.monkeyz stated, it takes extra processing each time you use an un-quoted index name (at least 10 times longer) because php first searches the defined constant table for a match, declares a NOTICE: level error (even if the error_reporting/display_errors settings hide them), decides you might have meant to use a quoted string, then searches for the quoted index name. By disabling any of the error_reporting settings, you also prevent logging of real problems that occur, such as when a hacker feeds your script all kinds of unexpected data that your validation logic does not detect. Code should not normally generate any kind of php errors when it executes, only for unexpected conditions. Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1048728 Share on other sites More sharing options...
mellis95 Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks for the help. It looks like I will be searching close to 50,000 lines of PHP for unquoted index names. Matt Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1048774 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 Sorry to pick, but if you are developing php applications that you are going to publish on the Internet for others to use, you must be aware of and follow basic proper php syntax such as using quotes around index names. Also, developing such an application on a system with full php error reporting turned on (which would have exposed the problem of not putting quotes around the array index names), not using short open tags (assuming you are), and not relying on register_globals or any of the other depreciated php language features would be prerequisites as well. Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1049264 Share on other sites More sharing options...
mellis95 Posted April 27, 2010 Author Share Posted April 27, 2010 On the comments below: I am still learning. In fact, I learn more every day. I only started really getting into PHP about a year ago and have been totally self-taught through a couple of books, some google searching, and these forums. The application that I have been working on is Open Source and I am not making a dime from it. Simply working on it as a learning experience and I figured that if others wanted to benefit in any small way from what I am working on, then they can freely have it to modify/contribute/use. I have definitely learned my lesson about developing with full error reporting, and as soon as I realized that I should have been doing that, I turned it on and began going back through the application working out the bugs. And, by the way, I am not using short open tags and register_globals is turned off. Sorry to pick, but if you are developing php applications that you are going to publish on the Internet for others to use, you must be aware of and follow basic proper php syntax such as using quotes around index names. Also, developing such an application on a system with full php error reporting turned on (which would have exposed the problem of not putting quotes around the array index names), not using short open tags (assuming you are), and not relying on register_globals or any of the other depreciated php language features would be prerequisites as well. Quote Link to comment https://forums.phpfreaks.com/topic/199800-quoting-array-elements/#findComment-1049279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.