EDIT 2: Changed the question to reflect the underlying issue.
EDIT 1: Seems like the weird-folder part is the culprit. I tried on a new project with other packages as well and all of them (including dependencies) are reproducing this behavior.

Original Issue:
I have implemented the Twilio SDK through composer. The project is quite old and and does not use any kind of framework or standard so what little order we may have has been implemented manually. We have our own autoloader so we do not use the psr-4 composer.json property.
My relevant project structure is as follows:
- api.php
- composer.json
- composer.lock
- vendor
- app
- models
- libraries
- controllers
- tools
- bootstrap.php
api.php file is the entrypoint for the application for this use case, which includes in its first line our bootstrap file:
<?php
require_once("app/tools/bootstrap.php");
The bootstrap file then includes 2 autoloaders, my custom one and composer's (assume the BASE_DIR variable is working correctly as well as my autoloader):
require_once(BASE_DIR . '/vendor/autoload.php');
require_once(BASE_DIR . '/app/tools/autoload.php');
For reference this is my app/tools/autoload.php content, it is tailored to the project structure:
<?php
spl_autoload_register(function ($className) {
$autoload_folders = ["controllers", "models", "libraries"];
$filename = str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
foreach ($autoload_folders as $folder) {
$path = BASE_DIR . "/app/$folder/$filename";
if (is_file($path)) {
require_once($path);
break;
}
}
});
When referencing $twilio = new \Twilio\Rest\Client($sid, $token); after the autoloaders have been required I get Uncaught Error: Class 'Twilio\Rest\Client' not found.
If I print something from the vendor/autoload.php file it is displayed in my application so it IS being included.
This was our installation process:
composer require twilio/sdk
composer update
Added require_once('/vendor/autoload.php') to our bootstrap file
I've tried (and still won't work):
- Running
composer dump-autoloadwith and without optimization (which shouldn't be necessary since we installed it fresh), - Moving the autoload to be the first line executed on api.php as require_once('vendor/autoload.php')
- Putting the Twilio code right after requiring the autoloader
What DID work but I refuse to do it this way is requiring the Twilio autoloader directly (vendor/twilio/sdk/<weird-twilio-folder-name>/src/autoload.php)
I've worked with Laravel for quite some time and have some of experience with composer, this also USED TO work before and now isn't... I'm pulling hairs here, is there something I'm missing?
composer.json file for reference:
{
"require": {
"twilio/sdk": "^7.16"
}
}