Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Cannot declare class ... because the name is already in use #40

Open
drbyte opened this issue Jul 18, 2019 · 1 comment

Comments

@drbyte
Copy link

drbyte commented Jul 18, 2019

Complete error message:
(occurs when running php artisan generate:model-factory)

PHP Fatal error:  Cannot declare class PragmaRX\Tracker\Data\Repositories\Session, because the name is already in use in /app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php on line 330

Symfony\Component\Debug\Exception\FatalErrorException: Cannot declare class PragmaRX\Tracker\Data\Repositories\Session, because the name is already in use

Background:
The PragmaRX Tracker package hasn't merged an important fix, so I've had to override it in my app with composer magic.

composer.json:

    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
+        "files": ["app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php"],
        "psr-4": {
            "App\\": "app/"
        }
    },

So, yes, my app does actually re-declare that class, but composer knows how to handle it.

Possible Solutions:

  1. Bandage: add an "exclude" flag to the generate:model-factory command, where we can list the things (ie: directories probably) to ignore.
  2. Auto-ignore things listed in composer.json's autoload.files key.
  3. Catch the error and just ignore it, instead of fatal abort.
  4. Tell the user (me!) I'm doing it wrong! (ie: I guess I could put these overrides outside app)
@drbyte
Copy link
Author

drbyte commented Jul 18, 2019

Workaround: for temporary dev-only use, I just removed those custom things, and the package generated factories normally without error. 👍

But if this were to be run in some automated fashion, then detecting this custom composer situation might be important ... hence my reason for posting this issue. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant