Search code examples
phpcomposer-phpautoloadplivo

Should autoload.php be included in class files


We're using this plivo package: https://github.com/plivo/plivo-php and the current version is throwing an error because it can't find the autoload file which they're requiring at the top of their class file.

<?php
namespace Plivo;
require 'vendor/autoload.php';
use Guzzle\Http\Client;
class PlivoError extends \Exception {}

From my experience the autoload file should only be included in the page that's actually going to be calling class's and functions.

Is this an error on their end or is there some way we can fix this within our own project that will persist through composer updates.


Solution

  • It's now fixed in my pull request for this library.

    Indeed it is wrong to reference any composer autoloading in a package itself. Composer will install a globally available autoloader that is able to load every class included in any composer.json description.