hisuwh Posted February 8, 2012 Share Posted February 8, 2012 I have the following array and function definition: $permissions = array('postEvent' => 6, 'editBlog' => 6); function permission($action){if (isset($_SESSION['type'])&&($_SESSION['type']>=$permissions[$action])){ return true;} else { return false;}} When I call the function - permission('editBlog') - I get the error message "Notice: Undefined variable: permissions" But the variable clearly is defined so I don't get the problem! Any help? Link to comment Share on other sites More sharing options...
Ingolme Posted February 8, 2012 Share Posted February 8, 2012 The variable was not defined inside the function. You have to bring it to local scope using the global keyword. function permission($action) { global $permissions; /* Code here */} Link to comment Share on other sites More sharing options...
thescientist Posted February 8, 2012 Share Posted February 8, 2012 you would need to define $permissions as global, or pass it in to the function. Link to comment Share on other sites More sharing options...
hisuwh Posted February 8, 2012 Author Share Posted February 8, 2012 Wow I never knew scope was an issue with php before.But makes sense really. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.