A: 

I would say it depends on your application's design. If the class is some general, loosly coupled class or module and suddenly it uses such global vars, that would be bad practice in my book. But if the class is clearly geared towards a specific task for which those specific global vars are needed anyway (eg your login example), I don't see any clear objections.

Daan
+3  A: 

To answer my own question, I'd say yes, it's fine to access super globals, provided you aren't modifying them to be accessed across multiple classes. There's no magic going on in the background - you're just reading the state, and super globals are how PHP provides that to you.

However, you should never, ever, ever modify a global within a class and access it somewhere else. That's when you make unit testing impossible.

Frank Crook
So this question is just you talking to yourself?
cletus
@cletus The FAQ tells you to post your answers to your own question using the answer form, and not to put it within your question. If it gets downvoted, I'll know I'm wrong, and with globals giving me an icky feeling, I need some sort of reassurance what I'm doing is right.
Frank Crook
+1 Downvote removed
karim79
"Just reading state" is bad enough. But I agree that reading global state is a lesser evil than writing it.
troelskn
+2  A: 

One approach is to wrap all superglobals into a class of its own. I'm pretty sure Zend Framework has a class of its own for e.g. manipulating Cookies.

Henrik Paul
+2  A: 

I wouldn't say there is a straight yes or no answer to this one. What the idea (with all superglobals $_GET $_POST $_SESSION) is that you are asking for data that sits in your entire application, and not local to the scope you are asking for.

What can happen with these superglobals is that what if they change somewhere for whatever reason just before or (god forbid) during the execution of your function. That can turn out to be a very annoying bug to reproduce.

So I would say it is bad form.

Ólafur Waage
+1 Very good point. I never modify super globals, so I haven't been thinking about them being modified elsewhere, and something relying on the data to be the same later.
Frank Crook
Maybe there's a way to lock super globals so they can't be changed after the script begins? I'll look into that.
Frank Crook