contao-community-alliance / composer-client

This is the Contao Composer Client
http://de.contaowiki.org/Composer
27 stars 18 forks source link

correctly check for minimum PHP version #287

Closed fritzmg closed 8 years ago

fritzmg commented 8 years ago

In /system/modules/!composer/config/config.php#L18 you check for the minimum PHP version:

if (version_compare(PHP_VERSION, '5.3', '<')) {
    trigger_error('Composer client requires PHP 5.3, even with Contao 2.11', E_USER_ERROR);
    return;
}

However, later on in other functions, you check for a more specific PHP version:

define('COMPOSER_MIN_PHPVERSION', '5.3.4');
if (version_compare(PHP_VERSION, COMPOSER_MIN_PHPVERSION, '<')) {
    return;
}

e.g. here and here.

However, you do this without throwing an Exception - you only return out of the function. This means that if a system is already running with some packages installed and the PHP version gets switched to >= 5.3.0, < 5.3.4 (e.g. because you are moving to another server but haven't checked its environment), you might suddenly get fatal errors from missing classes and the like, because you do a simple

return;

here in the initialization. This makes it difficult for the yet unknowing developer to find out why suddenly these fatal errors occur, since there is no indication, since the initial check in the config.php only checks for PHP 5.3, but not for PHP 5.3.4.

At the very least the aforementioned PHP check in config.php should simply be changed from

if (version_compare(PHP_VERSION, '5.3', '<')) {
    trigger_error('Composer client requires PHP 5.3, even with Contao 2.11', E_USER_ERROR);
    return;
}

define('COMPOSER_MIN_PHPVERSION', '5.3.4');
define('COMPOSER_DIR_RELATIVE', 'composer');
define('COMPOSER_DIR_ABSOULTE', TL_ROOT . '/' . COMPOSER_DIR_RELATIVE);

to

define('COMPOSER_MIN_PHPVERSION', '5.3.4');
define('COMPOSER_DIR_RELATIVE', 'composer');
define('COMPOSER_DIR_ABSOULTE', TL_ROOT . '/' . COMPOSER_DIR_RELATIVE);

if (version_compare(PHP_VERSION, COMPOSER_MIN_PHPVERSION, '<')) {
    trigger_error('Composer client requires PHP 5.3, even with Contao 2.11', E_USER_ERROR);
    return;
}

Then it will always be clear.