Fatal error "Class not found" with autoload [closed]

2

The autoload function is as follows:

<?php
spl_autoload_register(function ($_class){
  $aClass = explode('\', $_class);
  $class = end($aClass);
  $baseDir = __DIR__;
  $directories = glob($baseDir . '\*' , GLOB_ONLYDIR);

  foreach ($directories as $baseDir){
     $fileName  = $baseDir.'\';
     $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
     if (file_exists($fileName))
         require $fileName;
  }
});

I made an echo of the $ filename variable and the result was "C: \ wamp \ www \ projectx \ api \ v1 \ libs \ PayPal \ Auth \ OAuthTokenCredential.php" p>

I checked the path and it's correct.

Within the "OAuthTokenCredential.php" file I have the following code:

namespace PayPal\Auth;

use PayPal\Cache\AuthorizationCache;
use PayPal\Common\PayPalResourceModel;
use PayPal\Core\PayPalHttpConfig;
use PayPal\Core\PayPalHttpConnection;
use PayPal\Core\PayPalLoggingManager;
use PayPal\Exception\PayPalConfigurationException;
use PayPal\Exception\PayPalConnectionException;
use PayPal\Handler\IPayPalHandler;
use PayPal\Rest\ApiContext;
use PayPal\Security\Cipher;

class OAuthTokenCredential extends PayPalResourceModel{
    //...
}

The class name is correct, " OAuthTokenCredential ".

If the path to the class is correct, the class name is correct because it returns the error " Fatal error: Class 'OAuthTokenCredential' not found in ...     

asked by anonymous 10.03.2015 / 18:03

1 answer

2

When declaring the class, insert the namespace:

$otc = new \PayPal\Auth\OAuthTokenCredential

Or before declaring the class, make use of "use"

use \PayPal\Auth\OAuthTokenCredential
$otc = new OAuthTokenCredential();
    
12.03.2015 / 11:44