0

I'm trying to use composer. I want to run the composer -v command, but it gives me an error. I'm using a macOS device and have already uninstalled and installed composer using Homebrew several times. Here is the log information from composer:

PHP Warning:  PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0

Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0
PHP Fatal error:  Uncaught ErrorException: preg_match_all(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php:152
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'preg_match_all(...', 'phar:///usr/loc...', 152)
#1 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php(152): preg_match_all('#<(([a-z](?:[^\\...', '', NULL, 256)
#2 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php(135): Symfony\Component\Console\Formatter\OutputFormatter->formatAndWrap('', 0)
#3 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Output/Output.php(157): Symfony\Component\Console\Formatter\OutputFormatter->format('')
#4 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Output/Output.php(132): Symfony\Component\Console\Output\Output->write(Array, true, 16)
#5 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(836): Symfony\Component\Console\Output\Output->writeln('', 16)
#6 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(154): Symfony\Component\Console\Application->renderThrowable(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#7 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(177): Symfony\Component\Console\Application->Symfony\Component\Console\{closure}(Object(ErrorException))
#8 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/src/Composer/Console/Application.php(138): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/bin/composer(88): Composer\Console\Application->run()
#10 /usr/local/Cellar/composer/2.4.1/bin/composer(29): require('phar:///usr/loc...')
#11 {main}
  thrown in phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php on line 152

Fatal error: Uncaught ErrorException: preg_match_all(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php:152
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'preg_match_all(...', 'phar:///usr/loc...', 152)
#1 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php(152): preg_match_all('#<(([a-z](?:[^\\...', '', NULL, 256)
#2 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php(135): Symfony\Component\Console\Formatter\OutputFormatter->formatAndWrap('', 0)
#3 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Output/Output.php(157): Symfony\Component\Console\Formatter\OutputFormatter->format('')
#4 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Output/Output.php(132): Symfony\Component\Console\Output\Output->write(Array, true, 16)
#5 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(836): Symfony\Component\Console\Output\Output->writeln('', 16)
#6 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(154): Symfony\Component\Console\Application->renderThrowable(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#7 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Application.php(177): Symfony\Component\Console\Application->Symfony\Component\Console\{closure}(Object(ErrorException))
#8 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/src/Composer/Console/Application.php(138): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 phar:///usr/local/Cellar/composer/2.4.1/bin/composer/bin/composer(88): Composer\Console\Application->run()
#10 /usr/local/Cellar/composer/2.4.1/bin/composer(29): require('phar:///usr/loc...')
#11 {main}
  thrown in phar:///usr/local/Cellar/composer/2.4.1/bin/composer/vendor/symfony/console/Formatter/OutputFormatter.php on line 152

I also can't run any PHP commands. I tried php -r 'echo "test\n";' but it gives me the error below:

PHP Warning:  PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0

Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0
test

I tried restarting PHP using Homebrew, but still not working.

  • 2
    I wonder if your php is correctly installed. Can you run `php -i`, or `php -r 'echo "test\n";'` – aynber Sep 01 '22 at 15:01
  • I think that's the problem. Cause `php -r 'echo "test\n";'` is not working. I uninstalled and reinstalled php using Homebrew, but still, it happens. Here is the error: ```PHP Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0 Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0 test``` – Hossein hossein Sep 01 '22 at 15:03
  • Does a simple `php -v` work if so what version is it – RiggsFolly Sep 01 '22 at 15:04
  • Here is the result: ```PHP Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0 Warning: PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0 PHP 8.1.9 (cli) (built: Aug 4 2022 15:11:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.9, Copyright (c) Zend Technologies ``` – Hossein hossein Sep 01 '22 at 15:06
  • 1
    https://stackoverflow.com/questions/70040287/php7-4-preg-replace-compilation-failed-unrecognised-compile-time-option-bi suggests updating libpcre – aynber Sep 01 '22 at 15:06
  • How can I update it? I'm not familiar with it. Can you help me pleas? – Hossein hossein Sep 01 '22 at 15:11
  • How did you install PHP in the first place? Could it help to remove and reinstall it? – Nico Haase Sep 01 '22 at 17:55
  • Using Homebrew. I did reinstall it but still not helpful. I downgrade the PHP version to 7.4, and the PHP is now working, but the composer is still not working. – Hossein hossein Sep 02 '22 at 07:02
  • perhaps if it is an option for you: as an alternative to homebrew there is nix (the package manager) that also runs on a mac. me is not a mac user, but I know they have composer as a package and it will have a php runtime then independent to the one installed with homebrew (or any other in $PATH). see https://nixos.org/explore.html , https://search.nixos.org/packages?channel=22.05&show=php81Packages.composer&from=0&size=50&sort=relevance&type=packages&query=composer and https://nixos.org/download.html#nix-install-macos – hakre Sep 02 '22 at 18:11

0 Answers0