I have a very simple PHP/Composer application with the following structure:
- src
- content
- test
- Sandbox.php
Sandbox.php has only a static function to print "test" and its namespace is
namespace MyApplication\Content\Test;
My autoload.php has MyApplication an "autoload" property.
"autoload" : {
"psr-4": {"MyApplication\\": "src/"}
},
I run composer install --no-dev
in an Windows environment with XAMPP and in a test.php file I do (for the sake of a very simple test):
$autoloadFile = __DIR__ . '/wp-content/plugins/sandbox/vendor/autoload.php';
require $autoloadFile;
echo 'autoload = ' . file_exists($autoloadFile);
echo '<br />';
echo 'class_exists = ' . class_exists('MyApplication\Content\Test\Sandbox');
When I run this test.php file locally, it works perfectly. MyApplication is loading Sandbox class.
However, when I release this to my server which is a Linux based server but running on the same PHP version, Sandbox class is not found.
I made sure my /vendor/ folder is properly uploaded as well.
I'm wondering if the problem is happening because I'm running composer install on a Windows environment while it should be running the same command in my server (which I can't at the moment). Shouldn't the /vendor/ folder upload be enough to make the autoload classes work well?