Global variable overrides session variable in PHP

I found strange behavior in PHP, it looks like "inverted register globals." First try the following:

session_start(); $_SESSION['test'] = NULL; echo $_SESSION['test']; 

It doesn’t output anything. Then change line 2:

 session_start(); $test = 1; echo $_SESSION['test']; 

This prints "1"!

This only happens if I set $ _SESSION ['test'] to NULL!

Register global variables if 100% off.

My hosting provider has PHP 5.2.17. This does not happen on my local 5.3.6.

Is this a bug or is there a setting for this?

+4
source share
3 answers

The problem is solved!

I changed php.ini from:

 session.bug_compat_42 = On session.bug_compat_warn = Off 

To:

 session.bug_compat_42 = Off session.bug_compat_warn = Off 

Thanks Kerrek SB!

+2
source

This is not for me

http://sandbox.phpcode.eu/g/b61fd.php

Try contacting your support, but I think this is not possible.

0
source

Are you sure you are using PHP v5.2.17?

Check out

 <?php phpinfo(); ?> 

This should not happen in 4.3.0 and later.

0
source

All Articles