title: Should I store superglobals as the wrapper class' property or should I access it directly?
body: <p>I wanted to create a wrapper for <code>Session</code> and <code>Request</code> so that I don't have to access the PHP superglobals directly. I realized that if I create a wrapper for the superglobals and use them, unit testing my application will be easier as the wrapper class can be mocked.</p>
  
  <p>While trying to create my wrapper class, I researched some sample wrapper classes. Some of them stores the superglobal as a class property at initialization:</p>
  
  <pre><code>class Session
  {
      protected $vars;
  
      public function __construct()
      {
          session_start();
  
          // POINT OF INTEREST
          // Store the superglobal as a class property
          $this-&gt;vars = $_SESSION;
      }    
  
      public function get($index)
      {
          // POINT OF INTEREST
          // Accesses the class property instead of the superglobal
          return $this-&gt;vars[$index];
      }
  
      public function write($index, $value)
      {
          // Writes both class property and session variable
          $this-&gt;vars[$index] = $value;
          $_SESSION[$index] = $value;
      }
  }
  </code></pre>
  
  <p>My question: is there any particular reason why while creating a wrapper class we store the superglobal as the class' property instead of accessing them directly? Contrast the above code with this one:</p>
  
  <pre><code>class Session
  {
      public function __construct()
      {
          session_start();
      }
  
      public function get($index)
      {
          // Accesses the superglobal directly
          return $_SESSION[$index];
      }
  
      public function write($index, $value)
      {
          // Accesses the superglobal directly
          $_SESSION[$index] = $value;
      }
  }
  </code></pre>
  
  <p>IMO, since the wrapper class would be mocked anyway, why bother storing the superglobals as a class property? Is there a particular reason why so many people do this? Should I store the superglobals as a property in their wrapper instead of accessing it directly?</p>
  
  <p>Thanks for any input.</p>