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

dump() function not loaded if var-dumper and symfony share version #20201

Closed
rdohms opened this issue Oct 11, 2016 · 16 comments
Closed

dump() function not loaded if var-dumper and symfony share version #20201

rdohms opened this issue Oct 11, 2016 · 16 comments

Comments

@rdohms
Copy link
Contributor

rdohms commented Oct 11, 2016

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?

@fabpot
Copy link
Member

fabpot commented Oct 11, 2016

ping @nicolas-grekas

@nicolas-grekas
Copy link
Member

Right, that's how we decided to plug things then, to prevent a useless require of src/Symfony/Component/VarDumper/Resources/functions/dump.php when using symfony/symfony.
When using symfony/var-dumper, the file is required.
Not that even if you manage to have both symfony/symfony and symfony/var-dumper, composer gives no guarantee on the loading order, which means no guarantee on the actual version that will be loaded by the autoloader.

@Taluu
Copy link
Contributor

Taluu commented Oct 12, 2016

I remembered having stumbled on this case. IMO, the file * should * be required in symfony/symfony, because it is then in var-dumper. to fix that, I added in my iwn autoload-dev section the file pointing to the dump definition, but this is not practicable IMO...

I'm sure I mentionned this in a ticket, but I can't find it though :/

@rdohms
Copy link
Contributor Author

rdohms commented Oct 12, 2016

@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.

@apfelbox
Copy link
Contributor

I added in my iwn autoload-dev section the file pointing to the dump definition, but this is not practicable IMO...

Why is that not practical?

@Taluu
Copy link
Contributor

Taluu commented Oct 12, 2016

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)

@rdohms
Copy link
Contributor Author

rdohms commented Oct 12, 2016

agree with @Taluu here.

@apfelbox
Copy link
Contributor

@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.)

@Taluu
Copy link
Contributor

Taluu commented Oct 12, 2016

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

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Nov 21, 2016

See symfony/symfony-standard#1025
I know this is not exactly what you're asking for here, yet we decided to not require this file all the time, because it looked overkill.
Instead, I'm proposing to add this file to autoload-dev in the standard edition, which is generally where symfony/symfony is used to replace individual components.

@javiereguiluz
Copy link
Member

If I understood @nicolas-grekas correctly, we can close this as "fixed" by symfony/symfony-standard#1025 (not exactly a fix ... but it's close). Thanks!

fabpot added a commit to symfony/symfony-standard that referenced this issue Mar 10, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Add VarDumper's dump.php to autoload-dev

Pragmatical fix for symfony/symfony#20201

Commits
-------

7fe1143 Add VarDumper's dump.php to autoload-dev
@DreamiumGuy
Copy link

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.

thankyou guys.... you rock.. really saved my day today/ i was dump and dieing in kernel.php and it wont work..

@khelsisura
Copy link

Still facing the same problem sir

@xabbuh
Copy link
Member

xabbuh commented Jun 17, 2019

@harveyelsisura Please open a new issue with some instructions on how to reproduce if you think that something needs to be fixed.

@Yassine-Ezzedini
Copy link

I remembered having stumbled on this case. IMO, the file * should * be required in symfony/symfony, because it is then in var-dumper

please i'm having the same problem, can you like link me the screenshot on what to do exactly, i'm new to symfony and i've been sruggling for 3 days with it.

@tyteen4a03
Copy link

Any updates to the docs for this? I am using symfony/symfony and having trouble to get dump() in the global context.

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