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)

Commits related to this issue

Most upvoted comments

Always adding ./vendor/symfony/symfony/src/Symfomny/Component/VarDumper/Resources/functions/dump.php is 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/symfony dependency does not then really replace the package symfony/var-dumper (it should provide all the requirements and autoload stuff)

It is not good in require-dev also, because it won’t be included then (the *-dev are ignored when composer install non-root packages). I think that was the main reason why this file is not registered in the autoload section of symfony/symfony, but as the var-dmper is in the require section, it should belong in the normal autoload too

@Taluu ah, ok, that’s what I thought. I think just adding the entry to autoload-dev in symfony/symfony would 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.json is 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.php not being autoloaded by composer means its only available if Symfony boots up. Making it impossible to use dump() in tests or in other areas of code.

The only way i see to replicate this, is to add the dump.php file to the autoload/files of your root composer.json to then have it properly autoload, like @Taluu mentioned.

Maybe this should be in the docs somewhere.