How to access superglobals in correct way?
As the hint says, accessing the superglobals violates the encapsulation principle
A really basic approach would be:
class SessionObject
{
public $vars;
public function __construct() {
$this->vars = &$_SESSION; //this will still trigger a phpmd warning
}
}
$session = new SessionObject();
$session->vars['value'] = "newValue";
You can also have a look to the Symfony HttpFoundation Component for a full-fledged implementation