开发者

Global variable overrides session variable in PHP

开发者 https://www.devze.com 2023-03-28 09:19 出处:网络
I found weird behavior in PHP, it looks like \"reversed register globals\". First try this: session_start();

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.开发者_C百科

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


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!


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


Are you sure you are using PHP v5.2.17?

Check

<?php phpinfo(); ?>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消