Search code examples
fusionauth

How do I solve fusionauth php client error 'FusionAuthClient' not found?


when I follow https://github.com/FusionAuth/fusionauth-php-client

I can see error:

PHP Fatal error:  Uncaught Error: Class 'FusionAuthClient' not found ... on line 6

My application looks like this:

  First application
  <?php
  require_once 'FusionAuthClient.php';

  $apiKey = "7W-yBfeXfniDhu8PR_h0dGkSsPDJlpUYuP9rP2xXd_4";
  $client = new FusionAuthClient($apiKey, "http://localhost:9011");

line 6 is last.

composer says all is right

$ composer require fusionauth/fusionauth-client
Using version ^1.6 for fusionauth/fusionauth-client
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fusionauth/fusionauth-client (1.6.1)
    Downloading: 100%         

Writing lock file
Generating autoload files

FusionAuthClient.php, ClientResponse.php and RESTClient.php are in the same directory as my test script.

Can you point me into the right direction what is cause of this problem?


Solution

  • Have you looked at the first line of the FusionAuthClient.php file? apparently not.

    namespace FusionAuth;
    

    Therefore, the class is not in the global namespace, therefore you need to tell php which namespace it's in:

    $client = new FusionAuth\FusionAuthClient($apiKey, "http://localhost:9011");
    

    You're welcome.