JWT, composer internal error on Firebase\JWT\JWT

nitiphone2021

New member
According to I would like to try to use JWT for my PHP and these are my step

on domain/app/
composer require firebase/php-jwt

so I have
domain/app/login.php
domain/app/vendor/firebase/...

and on the login.php
Code:
		try{
		
		echo "1";
			require_once('vendor/autoload.php');
			
			use firebase\JWT\JWT;
			echo "2";
		} catch (Exception $e) {
			echo 'Caught exception: ',  $e->getMessage(), "\n";
		}

It's not show any thing and error "HTTP ERROR 500"
I think the code is really find the autoload.php but I don't know why it's internet error on line
use firebase\JWT\JWT;
If I add this command, the PHP will be error 500
 
In php the "use" keyword have two purpouses and php don't know which is in that code. Move require_once and use outside the try catch block on the beginning of the file, just after <?php
Use keyword can not be in a try catch or any other block if you want to load some class.
The use keyword can be inside class definition, but then it will be placed for trait inheritance.
 
Back
Top