?
avatar meddy
meddy
6 Jul 2015

A recent change to cms.php has broken bootstrapping a Joomla app under certain circumstances.

e1cfdc0#diff-fbf0c47a548d70d6a89b2493eb556dbc

The problem, as far as I've been able to tell, is this line:

$loader = require_once JPATH_LIBRARIES . '/vendor/autoload.php';

This assumes that the composer autoloader file has not been required already. The way require_once works is that if a file is required/included a second time that it will return 1 instead of the file. This means the next line:

$loader->unregister();

Fails with an error referencing a non-object, since 1 is not the \Composer\Autoload\ClassLoader object.

PHP Fatal error:  Call to a member function unregister() on a non-object in /var/www/451research/joomla/libraries/cms.php on line 34

A common reason that the composer autoloader would already be required is if you are bootstrapping a Joomla app within the context of a command line utility such as phpunit. We run our tests by referencing the phpunit executable in libraries/vendor/bin/phpunit. That executable file includes the composer autoloader.

I don't think it's reasonable to assume that cms.php will be the first to look at the composer autoloader, especially if you use command line libraries. For example, phpunit for tests, symfony console for tasks, or phinx for migrations.

I would provide a PR, but I'm unsure of the best course of action. The way Joomla unregisters the autoloader and then wraps it is unusual, and I'd like to see if there are any opinions on the issue first.

avatar meddy meddy - open - 6 Jul 2015
avatar mbabker
mbabker - comment - 6 Jul 2015

This is corrected already, see c47d015

avatar meddy
meddy - comment - 6 Jul 2015

Awesome! Thank you for your help. Should I assume this will be out in 3.4.4?

avatar mbabker
mbabker - comment - 6 Jul 2015

Should be.

avatar meddy
meddy - comment - 6 Jul 2015

cool thanks again

avatar meddy meddy - change - 6 Jul 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-07-06 19:57:10
Closed_By meddy
avatar meddy meddy - close - 6 Jul 2015
avatar zero-24 zero-24 - close - 6 Jul 2015
avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment