title: PHP - Calling class using variable with use keyword
body: <p>I'm looking to call a function in another file using a variable for the class name. When the user logs in, I get their access level and want to use the variable received to call different menus, pages, etc. that their access level allows them access to. So for example, they could have the following access:</p>
  
  <ul>
  <li>Administrator</li>
  <li>Employee</li>
  <li>Public</li>
  </ul>
  
  <p><code>$access</code> is set to one of these variables (string value).</p>
  
  <h1>1. In my <code>pages.php</code> script, I have the following (simplified):</h1>
  
  <pre><code>namespace Project\PageContent;
  
  use Project\PageContent as pageContent;
  
  class Administrator
  {
      public function pageAccess()
      {
          return "Administrator access";
      }
  }
  class Employee
  {
      public function pageAccess()
      {
          return "Employee access";
      }
  }
  class Public
  {
      public function pageAccess()
      {
          return "Public access";
      }
  }
  </code></pre>
  
  <h1>2. Now for the way I can access it (from another page - simplified):</h1>
  
  <pre><code>namespace Project\Main;
  
  use Project\Main as main;
  
  require_once('pages.php');
  use Project\PageContent as pageContent;
  
  $response = pageContent\Administrator::pageAccess();
  
  echo $response
  </code></pre>
  
  <h1>3. And for the way I'd like to access it (simplified) - where this obviously does not work or I wouldn't be asking the question:</h1>
  
  <pre><code>namespace Project\Main;
  
  use Project\Main as main;
  
  $access = 'Administrator';
  
  require_once('pages.php');
  use Project\PageContent as pageContent;
  
  $response = pageContent\.$access::pageAccess();
  
  echo $response;
  </code></pre>
  
  <p>Where $access represents a string that can be used to point to the proper class (in the case above - <code>Administrator</code>)</p>
  
  <p>The output of 3 should match the output of 2 and return <code>Administrator access</code></p>
  
  <p>Any help with this is greatly appreciated, thank you!</p>