简体   繁体   中英

PHP declaring global and session variables

I'm been using PHP5.3.8 for a while now and I've just come across a new error for me;

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

To which there is a solution to here; PHP session side-effect warning with global variables as a source of data .

However, I still don't understand why this is happening. As far as I'm aware, there should be no ambiguity between $foo and $_SESSION['foo'] ?

I've tried testing a few of the scripts online that people say throw this error, but they don't throw the warning on my system, and the script I'm getting this warning on is hella complicated and stripping it down to a few lines in order to replicate the error is proving problematic.

However, I have narrowed it down to one line;

$bonus = isset($_GET['bonus']) ? $_GET['bonus'] : '';

$_SESSION['bonus'] is set to null in a previous page, and register_globals has been off since about PHP4.2 something, so can't be the $_GET scope.

So this brings me back to my first point; why is there suddenly an issue between $bonus and $_SESSION['bonus'] ? I say suddenly, because I am using this exact script on another site (same box) and I get no errors.

Could someone point me to anywhere that perhaps explains in more detail how PHP deals with session vars etc and why there is an issue between the two variables?

Thanks.

[ Update ]

Looking here; PHP Runtime Configuration it does mention that:

[PHP has...] an undocumented feature/bug that allows you to initialize a session variable in the global scope...

I guess there may not be much more to say other than that. It just seems odd to me that PHP has issues with $_SESSION['foo'] / $foo when $_SESSION['foo'] != $foo ...

Try setting session.bug_compat_42 to off, it will turn off the functionality the warning is about. cf http://php.net/manual/en/session.configuration.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM