Search code examples
phpormdoctrine

php vendor/bin/doctrine [Warning] The use of this script is discouraged. - Why?


I'm using Doctrine ORM in my PHP project and I ran the following command to validate my schema:

php vendor/bin/doctrine orm:validate-schema

After running the command, I received a warning that says:

[Warning] The use of this script is discouraged. See [https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/tools.html#doctrine-console](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/tools.html#doctrine-console) for instructions on bootstrapping the console runner.

This happens for any Doctrine command I try to run, not just orm:validate-schema.

I've checked the Doctrine documentation but couldn't find clear information on why this warning is displayed or what the recommended best practices are.

Why is this script usage discouraged and what is the suggested alternative?


Solution

  • It is discouraged to use the script /vendor/bin/doctrine because it is generated by composer and all of your changes to that script (e.g. adding custom commands) might get overwritten on composer update or might be excluded from version control (as the /vendor directory usually is).

    Best practice is to add your own doctrine script (inside /bin/ for example) and make it executable. The warning will then be gone.