I'm using the Amazon Payments PHP SDK and the __autoload() is working fine in the browser but when I switch to my CLI scripts it just doesn't seem to be calling the function.
All I'm getting is "PHP Fatal error: Class 'OffAmazonPaymentsService_Client' not found".
I've put debugging into the __autoload() function to echo out the function being called and the file paths and nothing is printed in the terminal, just in the browser.
I've done a print_r(get_defined_functions()); and __autoload() is listed after the require_once() of the file it's in and is not listed before so I know it's getting the right function.
I've also checked the include_path being set and it's in the root of the Amazon Payments source folder which is where it should be so there's no reason why it wouldn't find the class OffAmazonPaymentsService_Client if __autoload() is called.
Can anyone advise why __autoload() isn't working in CLI? I'm not executing with php -a...
I have replaced the __autoload() within the AmazonPayments PHP SDK with spl_autoload_register() and that has worked.
/*
function __autoload($className){
$filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach($includePaths as $includePath){
if(file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)){
require_once $filePath;
return;
}
}
}
*/
spl_autoload_register(function($className){
$filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach($includePaths as $includePath){
if(file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)){
require_once $filePath;
return;
}
}
});