Page MenuHomePhabricator

Autoloader throws if class does not exist
Closed, DuplicatePublic

Description

I figured out why I was having issues with the Composer autoloader in D12874. In the PHP-Parser library, there exists the following code:

<?php

if (!class_exists('PhpParser\Autoloader')) {
    require __DIR__ . '/PhpParser/Autoloader.php';
}
PhpParser\Autoloader::register();

It seems that the issue is that __phutil_autoload will throw an Exception instead of allowing class_exists to return false. For a minimal example, consider the following code:

#!/usr/bin/env php
<?php

require_once dirname(__FILE__).'/__init_script__.php';

if (class_exists('FooBar')) {
  echo "Success!\n";
}