tags:

views:

182

answers:

5

Occassionaly I run accross this error in PHP, how can I fix this or what cause it?

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

A: 

error_reporting(0) disables all error messages.

danamlund
This is not a good solution. It will only hide issues with your code, and lead to future problems.
zombat
+1  A: 

Just disable session.bug_compat_42 and session.bug_compat_warn as the error message suggests.

Gumbo
Error messages exist for a reason and shouldn't be disabled during developemtn. At least make sure you understand why you're getting an error message before you disable it.
Otterfan
OK, now that I read stereoactive's advice I see why you might disable in this one case.
Otterfan
+2  A: 

You are relying on a deprecated feature of PHP, called register_globals. This feature caused many security issues, and shouldn't be used any longer. The PHP manual discusses this in-depth.

For an excellent description of the problem, see this Google Groups post.

Edit: If you aren't relying on register_globals, then you should pay attention to Gumbo and stereointeractive's answers.

zombat
+6  A: 

If your variable names are the same as the session parameters then this version of PHP will incorrectly recognize this as the programmer incorrectly relying on register_globals for session variables. Rename your variables and the warning should go away.

$mySessionVar = $_session["sessionVar"];

and not

$sessionVar = $_session["sessionVar"];
stereointeractive.com
Interesting. I never checked out `session.bug_compat_42` before. +1 for you and Gumbo.
zombat
A: 

I would NOT suggest you disable the warnings or error messages, this is a problem you probably want to fix. Either you have variables names that are triggering bogus error message (see sterrointerative.com's answer) or you're trying to use global variables without defining them (which means you likely have bugs you can't see). In my opinion that's an important difference you want to sort out.

If it's only happening on some pages, you're likely going to have to review all the code pulled into those pages and search for use of variables that don't appear to be defined before they are used. Stepping through those pages with a debugger ought to help.

acrosman
I store messages like error messages into a session variable, on a page load if this session is not null I display it, then I unset the session variable right after showing it, I notice this error only happens sometimes but everytime it does happen it is right after one of my messages is shown and then it will not unset it on that page either when this error occurs
jasondavis