faqts : Computers : Programming : Languages : PHP : Common Problems : Sessions and State

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 19 people (84%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Why can I not get session variables from functions within classes?

Dec 6th, 2000 18:06
Ben Munoz, Lloyd Parl,


The function only has access to locally defined variables and 
parameters passed in.  It therefore creates a new empty variable when 
you are really trying to access a session variable that is already 
defined. 
I usually do this:
function print_x() {
    global $x;// $x is your session variable, now you can use it
    print ($x);
}