How to know which version of Symfony I have?

PhpSymfony

Php Problem Overview


I know that I have downloaded a Symfony2 project and started with but I have updated my vendor several times and I want to know which version of symfony I have

Any idea ?

Php Solutions


Solution 1 - Php

Run app/console --version (for Symfony3: bin/console --version), it should give you a pretty good idea. On a random project of mine, the output is:

Symfony version 2.2.0-DEV - app/dev/debug

If you can't access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance:

const VERSION         = '2.2.0';

Just in case you are wondering, console creates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSION to initialize its parent constructor.

Solution 2 - Php

Although there are already many good answers I'd like to add an option that hasn't been mentioned. Using the command:

php bin/console about

you can get many details about the current project. The first section is about Symfony itself and looks like this:

-------------------- ------------------------------------------- 
 Symfony                                                         
-------------------- ------------------------------------------- 
 Version              4.2.3                                      
 End of maintenance   07/2019                                    
 End of life          01/2020                                    
-------------------- ------------------------------------------- 

I find the other information besides the version number very useful.

There are also other sections providing details about the (framework) Kernel, PHP, Environment.

Solution 3 - Php

Another way is to look at the source for Symfony\Component\HttpKernel\Kernel for where const VERSION is defined. Example on GitHub

Locally this would be located in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.

Solution 4 - Php

Use the following command in your Terminal/Command Prompt:

php bin/console --version

This will give you your Symfony Version.

Solution 5 - Php

also you can check the version of symfony and versions of all other installed packages by running

composer show

or

composer show | grep sonata

to get versions of specific packages like sonata etc.

Solution 6 - Php

If you want to dynamicallly display your Symfony 2 version in pages, for example in footer, you can do it this way.

Create a service:

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

 dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere. In Controller, wrap it in JSON, or in pages example footer

 <p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically update in your template.I know this is overkill but this is how I do it in my projects and it is working.

Solution 7 - Php

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

Check from Controller/ PHP File

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**

Solution 8 - Php

if you trying with version symfony

please try with

symfony 2 + >cmd>php app/console --version

symfony 3+ >cmd>php bin/console --version

for example

>D:project>php bin/console --version

Symfony 3.2.8 (kernel: app, env: dev, debug: true)

Solution 9 - Php

From inside your Symfony project, you can get the value in PHP this way:

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;

Solution 10 - Php

For Symfony 3.4

Check the constant in this file vendor/symfony/http-kernel/Kernel.php

const VERSION = '3.4.3';

OR

composer show | grep symfony/http-kernel

Solution 11 - Php

Maybe the anwswers here are obsolete... in any case, for me running Symfony 4, it is easy Just type symfony -V from the command line.

enter image description here

Solution 12 - Php

if you are in app_dev, you can find symfony version at the bottom left corner of the page

Solution 13 - Php

This page is the top Google result for search which version symfony using, and the top answers probably don't work anymore.

Apparently I'm on Symfony 5, after running symfony new aqua_note (from SymfonyCasts recommendation).

I had to ultimately run grep -r VERSION . | grep Kernel to see ./vendor/symfony/http-kernel/Kernel.php: public const VERSION = '5.4.2';... at least I think that's correct now.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzizoujabView Question on Stackoverflow
Solution 1 - PhpDiego AgullóView Answer on Stackoverflow
Solution 2 - PhpcezarView Answer on Stackoverflow
Solution 3 - PhpAdam ElsodaneyView Answer on Stackoverflow
Solution 4 - Phpuser2815519View Answer on Stackoverflow
Solution 5 - PhpPavel AlazankinView Answer on Stackoverflow
Solution 6 - Phpuser2338925View Answer on Stackoverflow
Solution 7 - PhpMohammad FareedView Answer on Stackoverflow
Solution 8 - PhpafeefView Answer on Stackoverflow
Solution 9 - PhpredreinardView Answer on Stackoverflow
Solution 10 - PhpYogesh YadavView Answer on Stackoverflow
Solution 11 - Phpsea26.2View Answer on Stackoverflow
Solution 12 - PhpjefView Answer on Stackoverflow
Solution 13 - PhpSteveExdiaView Answer on Stackoverflow