alekitto / class-finder

Utility classes to help discover other classes/namespaces
https://alekitto.github.io/class-finder/
MIT License
27 stars 5 forks source link

Incompatible with symfony/polyfill-php73 #1

Closed duskwuff closed 4 years ago

duskwuff commented 4 years ago

I like the concept of this package, but it's incompatible with some common packages like symfony/polyfill-php73 which define classes which conflict with PHP builtin classes:

iterator_to_array(new ComposerFinder);

PHP Fatal error: Cannot declare class JsonException, because the name is already in use in …/vendor/symfony/polyfill-php73/Resources/stubs/JsonException.php on line 12

alekitto commented 4 years ago

Thank you for your feedback. I'm trying to reproduce the error to find a possible solution.

A possible temporary workaround is to use the notPath method to exclude the problematic package/file. I'll keep you updated.

duskwuff commented 4 years ago

To reproduce:

composer require symfony/polyfill-php73
composer require kcs/class-finder
php <<EOF
<?php
require("vendor/autoload.php");
iterator_to_array(new Kcs\ClassFinder\Finder\ComposerFinder);
EOF
alekitto commented 4 years ago

@duskwuff I've just pushed a modification of the ComposerFinder which now should skip all the files already processed by composer classmap. Unfortunately, if the file is not in classmap definitions and is present inside a psr0/psr4 namespace a filter MUST be applied to avoid fatal errors or a non-including finder should be used (like PhpDocumentorFinder).

Can you please test the master branch and tell me if this problem is fixed?

duskwuff commented 4 years ago

That's solved the initial issue I ran into, but I'm still seeing some weird, intermittent issues while iterating over a variety of other Composer modules, including:

Some of these may represent bugs in the upstream code. For the time being, though, I'm probably going to have to take another approach from what I was planning. :/