This question already has an answer here:
- Using namespace in if / else statements 4 answers
I am trying to use Composer to auto-load the paths to a firebase/php-jwt library which is located on a different directory as my webpage.
Basically, the firebase/php-jwt library is in this path:
www/lib/vendor/firebase/php-jwt/src/JWT.php and the page trying to access the library is in this path: www/api/test.php
Here is my code to auto-load paths to library using Composer
if ($count > 0) {
require '../lib/vendor/autoload.php'; // autoload paths to libraries
// Class from firebase/php-jwt library
use \Firebase\JWT\JWT;
// create json-web-token (JWT)
$jwt = JWT::encode($payload, $secret_key);
}
However, I keep getting this error: Parse error: syntax error, unexpected 'use' (T_USE)
How do I solve this?
Edited So I have edited my question. My original question initially did not reflect the code within the 'if' block, but now I have updated my question to reflect that. So the problem was that 'use' must be declared in the outermost scope of a file (the global scope). I writing this down so that people know what the problem initially was. Anyways, thanks to all who tried to help in solving my question.
</div>