adhocore / php-jwt

Ultra lightweight, dependency free and standalone JSON web token (JWT) library for PHP5.6 to PHP8.2. This library makes JWT a cheese. It is a minimal JWT integration for PHP.
https://github.com/adhocore/php-jwt
MIT License
295 stars 21 forks source link

new JWT() - 500 Internal server error #32

Closed MateusOFCZ closed 2 years ago

MateusOFCZ commented 2 years ago

Hello, when I call the route with $jwt = new JWT('secret', 'HS256', 3600, 10); on code, returns Server Error 500, I'm using Docker:

api/test.php:

<?php
  include "../vendor/autoload.php";
    use Ahc\Jwt\JWT;

  $jwt = new JWT('secret', 'HS256', 3600, 10);
?>

Error on POST: image

In Try Catch return this error:

Error Object
(
    [message:protected] => Class 'Ahc\Jwt\JWT' not found
    [string:Error:private] => 
    [code:protected] => 0
    [file:protected] => /var/www/html/api/test.php
    [line:protected] => 8
    [trace:Error:private] => Array
        (
        )

    [previous:Error:private] => 
)

When I remove $jwt = new JWT('secret', 'HS256', 3600, 10); the error not occurred. Any idea how solve this?

adhocore commented 2 years ago

oh, it is autoload issue maybe? can you run composer dump-autoload -o once in the terminal from root dir?

also could you change from include to require _once for vendor/autoload.php?

btw, did you add adhocore/jwt in composer.json and run composer install first?