Robert
Robert

Reputation: 61

Global variable overrides session variable in PHP

I found weird behavior in PHP, it looks like "reversed register globals". First try this:

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

This outputs nothing. Then change line 2:

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

This outputs "1"!

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

Register globals 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?

Upvotes: 4

Views: 1394

Answers (3)

Robert
Robert

Reputation: 61

Problem 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!

Upvotes: 2

pat o.
pat o.

Reputation: 140

Are you sure you are using PHP v5.2.17?

Check

<?php phpinfo(); ?>

This shouldn't be happening in 4.3.0 and later...

Upvotes: 0

genesis
genesis

Reputation: 50976

It doesn't happen for me

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

Try to contact your support, but I think it's not possible

Upvotes: 0

Related Questions