Session, Function, Global

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Session, Function, Global

Post by Gen-ik »

Just a quick question..

If I wanted to use session variables in a function would I still need to use the global call ( example.. global $my_session_var; ) or are session variables global by default?


Thanks in advance.
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

they are global if you call them directly ($_SESSION['var']).

if you assign them at the beginning of the script ($var=$_SESSION['var']) you still need global.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

So.... I guess I would need to use the global method because when I first start my sessions I do something like..
session_register("my_session_var");
$my_session_var = "some value";


..?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

i guess so but since i never use session_register i don't know for sure. just test it!!
Post Reply