In the query example there is no problem, request, session and server information in PHP (pure) comes through global variables, in other
languages such infomations come through objects like java request, PHP frameworks also provide objects to manipulate this information.
What is not very correct to do is to access / manipulate a global variable within a function, the correct one is to pass this global as function argument, to avoid side effects such as breaking operation, a function should not suffer interference from nothing external should only depend on itself.