If you’re trying to start the basic Laminas skeleton application and the very first step of installation is failing, it would be fair to assume the project is going to be a mess moving forward. The good news is that moving past the PHP critical error is pretty easy.
PHP 7.4x, Composer 2.
The problem is during the initial step of installing the MVC Laminas framework using Composer 2 with PHP 7.4+.
composer create-project -s dev laminas/laminas-mvc-skeleton path/to/install
Generates the following error, which then produces a stack trace implicating OptionalPackagesInstaller.php
as the culprit.:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Console\Question\Question::__construct() must be of the type string, array given, called in /usr/share/php/Composer/IO/ConsoleIO.php on line 273 and defined in /usr/share/php/Symfony/Component/Console/Question/Question.php:38
Fear not! The fix is surprisingly easy. You’ll be editing the following file in your project folder:
vendor/laminas/laminas-skeleton-installer/src/OptionalPackagesInstaller.php
and correcting one mistake, the passing of an array instead of a string, in 2 different places:
- OptionalPackagesInstaller.php, Line 138: remove the opening bracket following the ‘=’ when setting the $question variable. Then, remove the closing bracket and the comma (around line 143).
- Same file, same concept: remove the brackets and unnecessary comma from the $question variable set in line 169.
Re-run composer install
after saving the corrected file. It should now prompt you for the installation options.
If it throws any issues regarding the installation of PHP modules, review how you installed PHP initially and address each issue accordingly.