swoole/library incompatibility ?
I created a simple Composer project that only depends on swoole/library and Psalm in a dev dependency.
Running any Psalm command results in a crash such as
$ ./vendor/bin/psalm --init
Calculating best config level based on project files
Uncaught RuntimeException: PHP Error: Constant SWOOLE_LIBRARY already defined in ~/test/vendor/swoole/library/src/constants.php:12 for command with CLI args "./vendor/bin/psalm --init" in ~/test/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:76
Stack trace:
#0 ~/test/vendor/swoole/library/src/constants.php(12): Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}()
#1 ~/test/vendor/composer/autoload_real.php(55): require('...')
#2 ~/test/vendor/composer/autoload_real.php(38): composerRequire75dacf6e10403b2eb197faf5b12fcc71()
#3 ~/test/vendor/autoload.php(25): ComposerAutoloaderInit75dacf6e10403b2eb197faf5b12fcc71::getLoader()
#4 ~/test/vendor/vimeo/psalm/src/Psalm/Internal/CliUtils.php(136): require_once('...')
#5 ~/test/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(247): Psalm\Internal\CliUtils::requireAutoloaders()
#6 ~/test/vendor/vimeo/psalm/src/Psalm/Internal/IncludeCollector.php(37): Psalm\Internal\Cli\Psalm::Psalm\Internal\Cli\{closure}()
#7 ~/test/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(243): Psalm\Internal\IncludeCollector->runAndCollect()
#8 ~/test/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run()
#9 ~/test/vendor/bin/psalm(120): include('...')
#10 {main}
(Psalm (unknown version) crashed due to an uncaught Throwable)
Note that I have the swoole extension installed and loaded with the parameter swoole.enable_library=off.
Same result if I use psalm/phar instead of vimeo/psalm.
However, I do have some other, more complex, projects depending on swoole/library for which using psalm/phar works (and vimeo/psalm does not) ... I am a bit puzzled.
The composer file :
{
"name": "test/psalm-swoole",
"description": "Psalm / Swoole test.",
"version": "0.1",
"require": {
"ext-swoole": "*",
"swoole/library": "6.0.*"
},
"require-dev": {
"vimeo/psalm": "6.4.*"
},
"autoload": {
"psr-4": {
"Test\\": "sources/"
}
},
"config": {
"vendor-dir": "vendor",
"optimize-autoloader": true
}
}
Hey @emmanuelGuiton, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.
With Psalm 6.13.* and PHP 8.4.*, the issue still exists but the symptoms have changed.
$ ./vendor/bin/psalm --init
Calculating best config level based on project files
PHP Warning: Constant SWOOLE_LIBRARY already defined in /home/nanu/tmp/swoole-test/vendor/swoole/library/src/constants.php on line 12
Warning: Constant SWOOLE_LIBRARY already defined in /home/nanu/tmp/swoole-test/vendor/swoole/library/src/constants.php on line 12
PHP Fatal error: Cannot redeclare function Swoole\Coroutine\run() (previously declared in @swoole/library/core/Coroutine/functions.php:16) in /home/nanu/tmp/swoole-test/vendor/swoole/library/src/core/Coroutine/functions.php on line 16
Fatal error: Cannot redeclare function Swoole\Coroutine\run() (previously declared in @swoole/library/core/Coroutine/functions.php:16) in /home/nanu/tmp/swoole-test/vendor/swoole/library/src/core/Coroutine/functions.php on line 16