I am trying to autoload a file and my PSR-4 autoloading worked fine locally however now that I am deploying to a baremetal server. It is not working and PHP states that it can’t find the autoloaded file. This is the current error:
Fatal error: Class ‘MetabaseModelsCron’ not found in /usr/www/users/metabase/src/commands/ArticleFetchCron.php on line 25
My composer.json is as follows:
{
"require": {
"vlucas/phpdotenv": "^2.4",
"guzzlehttp/guzzle": "6.3",
"monolog/monolog": "^1.23",
"illuminate/http": "^5.7@dev"
},
"autoload": {
"psr-4": {"Metabase\": "src/"}
}
}
The file that is having an issue is including the namespaces correctly as far as I know:
<?php namespace MetabaseCommands; // autoload composer require_once(__DIR__ . '/../../vendor/autoload.php'); /** * Class ArticleFetchCron * @package MetabaseCommands */ use MetabaseApiRequestsArticleRequest; use MetabaseModelsCron; use MetabaseModelsCronInterface; use MetabaseModelsDatabaseAdapter; class ArticleFetchCron extends Cron implements CronInterface
I am just wondering if I have perhaps made a mistake with my composer.json file?
Advertisement
Answer
The PSR-4 based class autoloader implemented by Composer, when asked to find MetabaseModelsCron, looks for a file called srcModelsCron.php. If your actual files are using a different case anywhere on the path such as srcmodelsCron.php you’ll get different results depending on whether the underlying file system is case sensitive or not. The reason is simple:
If the file system is case sensitive it can physically contain two directories called
srcmodelsandsrcModelsand you’re loading the wrong one.If it isn’t, both paths are actually identical to all effects.
Double-check file names and rebuild the autoloader with composer dump-autoload.