rhysnhall / etsy-php-sdk

PHP SDK for Etsy API v3.
MIT License
47 stars 36 forks source link

Fatal error: Uncaught Error: Class 'Etsy\Etsy\OAuth\Client' not found #30

Closed anzgar01 closed 6 months ago

anzgar01 commented 7 months ago

Hi there,

for some reason, my script fails at $client = new Etsy\OAuth\Client($api_key);

with the following error: Fatal error: Uncaught Error: Class 'Etsy\Etsy\OAuth\Client' not found

what could be the problem? I am using the code from the readme file. The Errors states "Etsy\Etsy", which might be the cause, but how do I change that?

I added the following, because I thought it might be missing, but that didn't help: require_once DIR . '/vendor/autoload.php';

Anyone got a clue what I might be doing wrong? Thanks in advance!

rhysnhall commented 6 months ago

@anzgar01 Add a backslash before $client = new Etsy\OAuth\Client($api_key);

$client = new \Etsy\OAuth\Client($api_key);

When importing a namespace you do not need a backslash. So this works:

use Etsy\OAuth\Client;

$client = new Client($api_key);

But if the namespace has not been imported, you must use an absolute identifier. You do this by adding the backslash, which defines the absolute path.

$client = new Etsy\OAuth\Client($api_key);

// If this script exists in a folder called Etsy then it look for the class starting at that point, as in: Etsy\Etsy\OAuth\Client