title: ZF2 using PHP5 vs PHP7
body: <p>I have a problem with my custom class located in:</p>
  
  <pre><code>module/SomeModule/src/SomeModule/Model/someClass.php
  </code></pre>
  
  <p>I get a database adapter like this using the <code>ServiceLocator</code> (exactly as <a href="https://framework.zend.com/manual/2.4/en/tutorials/tutorial.dbadapter.html" rel="nofollow noreferrer">in this <strong>Learning Zend Framework 2</strong> tutorial</a>): </p>
  
  <pre><code>public function getAdapter()
  {
    if (!$this-&gt;adapter) {
      $sm = $this-&gt;getServiceLocator();
      $this-&gt;adapter = $sm-&gt;get('Zend\Db\Adapter\Adapter');
    }
    return $this-&gt;adapter;
  }
  </code></pre>
  
  <p>In PHP 5 it works just fine, but in PHP 7 it doesn't. It seems that the class is no longer <code>ServiceLocatorAware</code> in PHP 7. And gives this error:</p>
  
  <pre><code>Fatal error: Uncaught Error: Using $this when not in object context in C:\Zend9\Apache24\htdocs\Project\module\Account\src\Account\Model\User.php:316 
  Stack trace:
  #0 C:\Zend9\Apache24\htdocs\Project\module\Account\src\Account\Model\User.php(271): Account\Model\User::getAdapter()
  #1 C:\Zend9\Apache24\htdocs\Project\module\Account\src\Account\Controller\LoginController.php(40): Account\Model\User::userLogin('xxx', 'xxx')
  #2 C:\Zend9\ZendServer\data\libraries\Zend_Framework_2\2.4.9\library\Zend\Mvc\Controller\AbstractActionController.php(82): Account\Controller\LoginController-&gt;indexAction()
  #3 [internal function]: Zend\Mvc\Controller\AbstractActionController-&gt;onDispatch(Object(Zend\Mvc\MvcEvent))
  #4 C:\Zend9\ZendServer\data\libraries\Zend_Framework_2\2.4.9\library\Zend\EventManager\EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #5 C:\Zend9\ZendServer\data\libraries\Zend_Framework_2\2.4.9\library\Zend\EventManager\EventManager.php(205): Zend\EventManager\EventManager-&gt;trigg
  in C:\Zend9\Apache24\htdocs\Project\module\Account\src\Account\Model\User.php on line 316
  </code></pre>
  
  <p>Anyone can tell me why there is this difference between PHP 5 and PHP 7 and how to resolve it?</p>