Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/199800-quoting-array-elements/
Share on other sites

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.