phpeclipsecomposer-phpautoloadpsr-0

Error "Class not found" using Composer PSR-0 autoloader on Eclipse Neon PDT


I am currently trying to build a new PHP project from scratch (inside a git repository), using Composer (for the very first time), on Eclipse Neon PDT with Composer Eclipse Plugin and EGit.

In order to start with something quite simple, I first installed the well-known library PHP Markdown Lib. I think that I had not getting problem for configuring the require setting, as running Composer correctly updates dependencies using:

"require" : {
    "php" : ">=5.3",
    "michelf/php-markdown" : "~1.7"
},

As described in the Usage section of the documentation of PHP Markdown Lib, I setup a PSR-0-compatible autoloader in my composer.json and generated the autoload file:

"autoload" : {
    "psr-0" : {
        "Michelf\\Markdown" : "vendor/michelf/php-markdown/Michelf"
    }
},

On my PHP file, I have simply included the following:

$input = file_get_contents('input.md');
use Michelf\Markdown;
$output = Markdown::defaultTransform($input);

All seem to be correctly recognized by Eclipse Neon:

  1. the namespace and class rightly appear as autocomplete propositions (first screenshot)
  2. the library is displayed in the outline of the document as import declarations (second screenshot)

namespace-class

outline

But, despite all my testings with these settings, the page is still displaying:

Fatal error: Class 'Michelf\Markdown' not found

I have tested other formulations, such as use \Michelf\Markdown;: it is equally recognized by Eclipse Neon (autocomplete feature and document outline, as displayed on previous screenshots), but I still get the fatal error.

To ensure the autoload file was updated correctly, I have also executed the CLI dump-autoload command. Unfortunately, without more success at this time.

Right now, I suppose this problem seems to be not directly related with PHP Markdown Lib, but that I certainly forgot a step or made a mistake within my settings, which seem to fail to correctly set up the PSR-0 autoloader, even if all seem to be correctly detected by the Eclipse IDE.


Solution

  • Did you remember to include composer autoload at the beginning of the file?

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