| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | 0.7.26 |
| Installed as | composer dependency |
There seems to be some kind of problem in a project using lstrojny/functional-php. What I've seen so far is that seems to crash when a file imports a function that was already imported in another file. Related issues #3145. I've created an example repository with failing code.
https://github.com/theUniC/rectorphp-report-issue
The CLI I've used is
php vendor/bin/rector process --dry-run -vvvvv
To finish the process without fatal errors.
It seems to be related to the auto_import_names parameter. I've run the command line (in the same repository) with this parameter commented out, and worked as expected.
Hi, I tried to reproduce:
git clone [email protected]:theUniC/rectorphp-report-issue.git
cd rectorphp-report-issue
composer install
php vendor/bin/rector process --dry-run --debug
vendor/bin/rector --version
# Rector v0.7.26
And result is as expected:

Thanks for testing.
I need to reproduce this in a the same repository too. How can we make that happen?
Also, copy-pasted text of the last error your get would be better, as I can't read the gif that quickly :smile:
Here you have the full output
File "/Users/christian/workspace/php/rectorphp-report-issue/vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 73"
File "/Users/christian/workspace/php/rectorphp-report-issue/vendor/rector/rector/../../autoload.php" is about to be loaded in "AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 105"
File "/Users/christian/workspace/php/rectorphp-report-issue/vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 73"
File "/Users/christian/workspace/php/rectorphp-report-issue/vendor/rector/rector/../../autoload.php" is about to be loaded in "AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 105"
Rector v0.7.26
Config file: rector.yaml
[parsing] src/App/Kernel.php
[parsing] src/TheUniC/OldNamespace/Class1.php
[parsing] src/TheUniC/OldNamespace/Class2.php
[refactoring] src/App/Kernel.php
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[refactoring] src/TheUniC/OldNamespace/Class1.php
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
[applying] Rector\Renaming\Rector\Namespace_\RenameNamespaceRector
PHP Fatal error: Cannot redeclare Functional\map() (previously declared in /Users/christian/workspace/php/rectorphp-report-issue/vendor/lstrojny/functional-php/src/Functional/Map.php:24) in /Users/christian/workspace/php/rectorphp-report-issue/vendor/lstrojny/functional-php/src/Functional/map.php on line 24
Fatal error: Cannot redeclare Functional\map() (previously declared in /Users/christian/workspace/php/rectorphp-report-issue/vendor/lstrojny/functional-php/src/Functional/Map.php:24) in /Users/christian/workspace/php/rectorphp-report-issue/vendor/lstrojny/functional-php/src/Functional/map.php on line 24
Additionally I've created a new release on that repo which contains a tar with the local clone. Does that work for you ?
https://github.com/theUniC/rectorphp-report-issue/releases/tag/1.0.0
Thanks!
hi @TomasVotruba !
I have a very minimal reproducer:
https://github.com/bendavies/rector-functional-php
The problem is auto_import_names: true in rector.yaml
Remove that and the issue does not occur.
Thanks
Without auto_import_names, it works for me also, however, all the /** @var whatever */ is fully qualified rather than being added to the imports
(that may sound obvious but yeah that makes it unworkable for my use case, we prefer imports over \fully\qualified\Packages)
Is there any other workaround?
@bendavies I'm sorry, I've just now noticed your reply.
Could add failing Github Action there with updated Rector 0.8.16, so we know the problem persist? It would be much smoother to debug it then.
This reply is relevant to everyone who is having this issue. Minimal reproducible repository will improve chances to fix it.
@TomasVotruba will do! thanks
@TomasVotruba done, but it doesn't happen on GitHub actions 😢
I can still reproduce in that repo locally though.
Would appreciate if you could try with a clone of that repo too!
Thanks!
It's reproducible locally with the official docker image too:
docker run -v $PWD:/app -w /app --rm -it php:7.4-cli-alpine3.12 vendor/bin/rector process
I switched GitHub actions to use the php:7.4-cli-alpine3.12 docker image and it still passes!
Not sure what else to try
Alpine is not good for testing, Symfony reported some bugs for it and we run on Symfony mostly, so it might be false positive.
@bendavies I cloned your repository and I got same error even at dev-master, It seems related with autoload somewhere:
➜ rector-functional-php git:(master) ✗ php vendor/bin/rector process --dry-run -vvvvv --debug
File "/Users/samsonasik/www/rector-functional-php/vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 100"
File "/Users/samsonasik/www/rector-functional-php/vendor/rector/rector/../../autoload.php" is about to be loaded in "AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 134"
Rector 0.8.56
Config file: rector.php
[parsing] src/test.php
[refactoring] src/test.php
[post rectors] src/test.php
Fatal error: Cannot redeclare Functional\map() (previously declared in /Users/samsonasik/www/rector-functional-php/vendor/lstrojny/functional-php/src/Functional/Map.php:24) in /Users/samsonasik/www/rector-functional-php/vendor/lstrojny/functional-php/src/Functional/map.php on line 24