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? 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. 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? 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 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. 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! Link to comment https://forums.phpfreaks.com/topic/186480-function-question/#findComment-984735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.