symfony: dump() function not loaded if var-dumper and symfony share version
This may be a composer issue, but I’ll start the investigation here.
Currently my project uses symfony/symfony: 2.8.*
Scenario 1
Requiring symfony/var-dumper:ˆ2.8|^3.0 means that the replace entry in symfony/symfonykicks in. This means for example that composer show does not list those packages, just symfony/symfony.
By the documentation, all we need to do to use dump() is enable the DebugBundle. However doing this loads dump, but not before the container/bundles are processed, meaning that if you try a dump() in the AppKernel itself it says “function does not exist”.
Scenario 2
If you install symfony/var-dumper:^3.1, a version that is not “replaced” by the symfony/symfony version, it will be loaded in an entire new way. It now shows up in composer show and it also does one more thing: it adds the dump.php file to the autoload_files loader, which does not happen in scenario 1.
Now it seems to me as if the autoload entry should be considered regardless of the replaces definitions, right?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (12 by maintainers)
Always adding
./vendor/symfony/symfony/src/Symfomny/Component/VarDumper/Resources/functions/dump.phpis bothersome, it should be done automatically IMO, as this is a dependency for the var-dumper, and it is in the var-dumper…the
symfony/symfonydependency does not then really replace the packagesymfony/var-dumper(it should provide all the requirements and autoload stuff)It is not good in
require-devalso, because it won’t be included then (the*-devare ignored when composer install non-root packages). I think that was the main reason why this file is not registered in theautoloadsection ofsymfony/symfony, but as thevar-dmperis in therequiresection, it should belong in the normalautoloadtoo@Taluu ah, ok, that’s what I thought. I think just adding the entry to
autoload-devinsymfony/symfonywould be the proper way, too. 👍(I wasn’t sure whether you initially meant that symfony adding this entry is no good solution or whether manually doing it yourself in every project’s
composer.jsonis no good. Obviously you meant the latter, what I completely agree with.)@nicolas-grekas not really worried about the version here, but that fact that
src/Symfony/Component/VarDumper/Resources/functions/dump.phpnot being autoloaded by composer means its only available if Symfony boots up. Making it impossible to usedump()in tests or in other areas of code.The only way i see to replicate this, is to add the
dump.phpfile to the autoload/files of your rootcomposer.jsonto then have it properly autoload, like @Taluu mentioned.Maybe this should be in the docs somewhere.