A coworker of mine and I disagree on this argument, however. It's funny, because we are working on a project together. All of his class functions that need a session var, he makes it a parameter, like this:
function changePassword ($username) {
...
}
I never do this... I always assume the $_SESSION var is available inside my functions. I do this:
function changePassword() {
$username = $_SESSION['username'];
...
}
Which is better? Well, that all depends. My version makes it clear that I will use $_SESSION['username']. Users of this class function cannot pass the username they want to change, making it more secure and foolproof. The function is clearly meant to change the password that corresponds to the username tied to this session. So, why give users of the class the ability to pass in any old username they want?