We are actually migrating our PHP project from PHP 5.3 to 7.2.
I recently migrate many libraries to Composer.
I have a problem to replace PHPExcel
with PhpSpreadSheet
which doesn't support PHP 5.3.
I keep PHPExcel
in a separate folder for the moment and I use PHP_VERSION_ID
to use either one or the other.
// early in the file to use another dependency
require_once 'vendor/autoload.php';
.
.
.
if (PHP_VERSION_ID > 50400) {
$workbook = new PhpOffice\PhpSpreadsheet\Spreadsheet();
} else {
require_once 'lib/PHPExcel/Classes/PHPExcel.php';
$workbook = new PHPExcel();
}
For the moment, our code must keep running under PHP 5.3 and 7.2.
Is there a solution to tell Composer autoloader to not autoload PhpSpreadSheet
under PHP 5.3?
Composer's autoloader will not load any class as long you're not request it. So the simplest option to tell Composer to not loading specified class, is to not using it. :)
However migrating from PHP 5.3 to 7.2 is a big task, trying to make your app compatible with both these version may make it really hard. I suggest to treat this as two separate versions developed on different branches with different PHP version required. It should be easier to have two lines where one should care only about PHP 5.3 and second only about PHP 7.2, than hacking one line to be compatible with both PHP 5.3 and 7.2. PHP 5.3 was released in 2009 - its ~7 years older than PHP 7.2, and many things was changed at this time.