Take an example login()function in class Account.
class Account {
public function login() {
if(isset($_POST['username']) && isset($_POST['password']))
return $this->_formLogin();
else if(isset($_SESSION['accountId']))
return $this->_sessionLogin();
else if(isset($_COOKIE['username']) && isset($_COOKIE['password']))
return $this->_cookieLogin();
else return false;
}
private function _formLogin() {
}
}
Try at this point to ignore any concerns about invisible methods for disinfecting data, salting passwords, etc. Focusing strictly on login(), is this global access bad juju? I avoid using PHP super globals inside classes normally, but I can't think of a good reason not to do this in this situation.
I can understand why you do not want magic in the background to occur when global classes interact with classes, but these global variables are built into PHP, are not modified by the class, and are used only by this class.
, , :
$user = new Account($whatever, $objects, $we, $depend, $on);
if($user->login()) {
}
, , , :
$user = new Account($whatever, $objects, $we, $depend, $on);
if(isset($_POST['username']) && isset($_POST['password']))
$user->formLogin($_POST['username'], $_POST['password']);
else if(isset($_SESSION['accountId']))
$user->sessionLogin($_SESSION['accountId']);
else if(isset($_COOKIE['username']) && isset($_COOKIE['password']))
$user->cookieLogin($_COOKIE['username'], $_COOKIE['password']);
if($user->isLoggedIn() {
}
, , ?