shane18 Posted December 28, 2009 Share Posted December 28, 2009 If I have a variable.... $_SESSION["USER_ID"]; to use that data in a function would i had to include it like this blah($_SESSION["USER_ID"],0,24,53,"bbblllaaahhh"); cuz don't functions only have access to whats sent to them or is created in them? Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/ Share on other sites More sharing options...
Brandon_R Posted December 28, 2009 Share Posted December 28, 2009 You can pass the value as an argument or globalize it. Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984728 Share on other sites More sharing options...
shane18 Posted December 28, 2009 Author Share Posted December 28, 2009 globalize it? is $_SESSION a global? and how can u globalize something? Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984731 Share on other sites More sharing options...
Brandon_R Posted December 28, 2009 Share Posted December 28, 2009 Oh i thought you meant a normal variable created outside the function and you want access to it inside the function, Session is just one of the superglobals and can be referenced in the globals array. $GLOBALS['_SESSION']['user_id'] would contain the same as $_SESSION['user_id'] can be used anywhere, ie in functions etc Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984732 Share on other sites More sharing options...
oni-kun Posted December 28, 2009 Share Posted December 28, 2009 If I have a variable.... $_SESSION["USER_ID"]; to use that data in a function would i had to include it like this blah($_SESSION["USER_ID"],0,24,53,"bbblllaaahhh"); cuz don't functions only have access to whats sent to them or is created in them? $_POST, $_SESSION, $_GET, $_REQUEST, $_SERVER are all 'super globals' already and don't need to be passed through to the function, You don't have to worry about that. EDIT: Brandon_r, and OP, read this: http://php.net/manual/en/language.variables.predefined.php It's of relevance. Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984733 Share on other sites More sharing options...
shane18 Posted December 28, 2009 Author Share Posted December 28, 2009 Thanks, got it all figured out! Quote Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.