{
    "href": "/post/2014/01/31/composer-undefined-method-related-to-global-install/",
    "relId": "2014/01/31/composer-undefined-method-related-to-global-install",
    "title": "Composer: Undefined Method Related To Global Install",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/aura/",
            "relId": "aura",
            "title": "Aura",
            "author": null,
            "created": "2020-09-14 21:51:57 UTC",
            "updated": [
                "2020-09-14 21:51:57 UTC"
            ],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2014-01-31 17:01:40 UTC",
    "updated": [
        "2014-01-31 17:01:40 UTC"
    ],
    "html": "<p>I just updated the <a href=\"http://auraphp.com\">Aura</a> v2 libraries to use <a href=\"http://php-fig.com/psr/psr-4\">PSR-4</a> via <a href=\"http://getcomposer.org\">Composer</a> instead of their custom <code>autoload.php</code> files, but when I started my integration tests for the <a href=\"https://github.com/auraphp/Aura.Project_Kernel\">Aura.Project_Kernel</a>, I got this error:</p>\n<pre id=\"scroll_to_here\"><code>PHP Fatal error:  Call to undefined method ComposerAutoloadClassLoader::setPsr4() in /Users/pmjones/Code/auraphp/develop-2-projects/Aura.Project_Kernel/cli-project/vendor/composer/autoload_real.php on line 38\n</code></pre>\n<p>Even after a <code>composer self-update</code> the problem remained.</p>\n<p>It turns out the problem was related to having issued <code>composer global require phpunit/phpunit=3.7.*</code>. The various Composer global vendor files were overriding the local ones in the project.  I discovered this only by calling <code>var_dump(get_included_files())</code> in the project-specific <code>autoload_real.php</code> file.</p>\n<p>I ended up deleting <code>~/.composer</code> (the global Composer location) and re-installing <a href=\"http://phpunit.de\">PHPUnit</a>, but looking back on it, perhaps a <code>composer global update</code> would have solved the problem as well.</p>\n<p><strong>UPDATE:</strong> Christophe Coevet in the comments indicates <code>composer global dump-autoload</code> would have done the trick as well.</p>\n<hr>\n<p class=\"reddit-links\">Read the Reddit discussion about this post <a href=\"https://www.reddit.com/r/PHP/comments/1wnmn5/composer_undefined_method_related_to_global/\">here</a>.</p>\n"
}
