How to autoload, so composer packages work correctly? I'm trying to load in a composer package: archwisp/php-encrypt-data, and while I'm able to use it in a test php script, using it in Drupal itself doesn't seem to be working.

This is the test script:

require __DIR__ . '/vendor/autoload.php';

$encryptionKey = 'IyJQdVtyNClqQ+ybuxHWNhJnw93ocxJuLruRztQPNI0=';
$macKey = 'pbJqXp4YhhtRYv/Ntt/i+O4KbO1F4/2bktO08m0+Exo=';

$phpcrypt = new \PHPEncryptData\Simple($encryptionKey, $macKey);

$ciphertext = $phpcrypt-&gt;encrypt('Foobar');

echo $ciphertext . "\n";

echo $phpcrypt-&gt;decrypt($ciphertext) . "\n";


But, I don't understand what I have to do in a Drupal class to make this work.  I tried to use archwisp\PHPEncryptData; at the top of the file, and I tried doing require DRUPAL_ROOT . '/vendor/autoload.php'; as well, but no matter what, it always says: Call to undefined function PHPEncryptData\\mcrypt_get_key_size()

Is it because it didn't do the autoload the same way, or is it getting mixed up because of namespaces?  The error is coming from the composer package itself, so it is locating that, but for some reason it's not calling the mcrypt function correctly, even though the extension is enabled and working in the test script.
Call to undefined function PHPEncryptData\mcrypt_get_key_size()


mcrypt is a php function of the mcrypt extension. Autloading is working perfectly fine, or you wouldn't get that far. You're simply missing that extension.

The error message is a bit confusing because PHP always looks for functions in the global namespace and in the namespace the code is in and then prints the error for the one with the namespace.