title: how to include php file contains 'use' command in another file with class
body: <p>I have two files.</p>
  
  <p>in the first file (Facebook.php) i take user data via Facebook (Facebook access token):</p>
  
  <pre><code>&lt;?php
  
      require_once '../include/Config.php';
      require_once ( '../libs/facebook/autoload.php' );
  
      use Facebook\FacebookSession;
      use Facebook\FacebookRequest;
      use Facebook\FacebookRequestException;
  
      function getUserData($token){
  
        // init app with app id and secret
        FacebookSession::setDefaultApplication( FB_APP_ID,FB_APP_SECRET ); //
  
        // If you already have a valid access token:
        $session = new FacebookSession($token); // 'access-token'
  
        // To validate the session:
  
        try {
  
             $session-&gt;validate();
  
        } catch (FacebookRequestException $ex) {
  
             // Session not valid, Graph API returned an exception with the reason.
             echo $ex-&gt;getMessage();
  
        } catch (\Exception $ex) {
  
              // Graph API returned info, but it may mismatch the current app or have expired.
              echo $ex-&gt;getMessage();
        }
  
       if($session) {
  
               try {
  
                    $user_profile = (new FacebookRequest( $session, 'GET', '/me'))-&gt;execute()-&gt;getGraphObject()-&gt;asArray(); //(GraphUser::className());
  
  
                    // print profile data
                    echo '&lt;pre&gt;' . print_r( $user_profile, 1 ) . '&lt;/pre&gt;';
  
                    return $user_profile;
  
                } catch(FacebookRequestException $e) {
  
                     echo "Exception occured, code: " . $e-&gt;getCode();
                     echo " with message: " . $e-&gt;getMessage();
                }
        }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>and this is the second file for manage user data:</p>
  
  <pre><code>&lt;?php
  
     require_once '../../../include/Facebook.php';
  
     class userManager {
  
         function __construct() {
  
      }
  
     /**
     * Get user data from facebook
     * @param user key
     * @return user data if exist else false
     */
     public function facebookSignIn($token){
  
          $fbUserData = getUserData($token);
  
          print_r($fbUserData);
     }
  }
  ?&gt;
  </code></pre>
  
  <p>in the second file i want to manage user data with a class but i think that my script don't run because the code lines in Facebook.php </p>
  
  <pre><code>use Facebook\FacebookSession; 
  use Facebook\FacebookRequest; 
  use Facebook\FacebookRequestException;
  </code></pre>
  
  <p>causing an error in compiling time.</p>
  
  <p>if I comment out these lines my script compiles but naturally doesn't retrieve facebook user data.</p>
  
  <p>what is the right way to include 'facebook.php' in my class?
  where am I wrong?</p>
  
  <p>I apologize but I do not understand 'use' command and how I can use it.</p>
  
  <p>If i include Facebook.php in a test file without class: </p>
  
  <pre><code>&lt;?php
  
       require_once '../include/Facebook.php';
  
       $token = $_GET["token"];
  
       getUserData($token);
  ?&gt; 
  </code></pre>
  
  <p>the script run fine!</p>