Sófka
Sófka

Reputation: 993

global and $_SESSION variables with the same name are the same

I got a piece of code:

$_SESSION['cms_lang'] = 2;
global $cms_lang;
$cms_lang[1] = 'en';

Error:

Cannot use a scalar value as an array

Problem is that, I really don't know why server sees my global variable as the same as $_SESSION variable. I used this piece of code a couple of times and never had problem with that. I guess it must depends of settings on server. Can anyone know how to force server to not take global and session variables with the same name as the same?

Upvotes: 1

Views: 157

Answers (1)

dvir
dvir

Reputation: 5115

You may read up on the PHP configuration setting register_globals which enables this behavior.

Also, read about why you should disable it (and generally, upgrade your PHP version!)

Upvotes: 5

Related Questions