Forem

Sarfraz Ahmed
Sarfraz Ahmed

Posted on • Originally published at codeinphp.github.io on

3

Semantic Versioning and Composer

Today any seriously written application/software follows the Semantic Versioning (also called SemVer). It boils down to this (emphasis mine):

  1. MAJOR version when you make incompatible API changes
  2. MINOR version when you add functionality in a backwards-compatible manner
  3. PATCH version when you make backwards-compatible bug fixes

Let's take example of Symfony framework which follows SemVer. As of this writing, its stable version stands at 2.6.6

Symfony Versioning

+-------+---------+ | Name | Version | +-------+---------+ | MAJOR | 2 | +-------+---------+ | MINOR | 6 | +-------+---------+ | PATCH | 6 | +-------+---------+

Here, we can see that MINOR and PATCH versions are backwards-compatible. This means if you install Symfony version 2.0.0 or 2.x.x with x being any number, it will be backwards-compatible. Meaning if you had initially installed Symfony version 2.0.0 and now you want to install version 2.6.6, you can do so without worrying it breaking functionality. However when Symfony announces a version starting with 3 as MAJOR version then it will most likely break some of the functionality with all previous version less than 3.x.x. Thanks to SemVer, we can easily find that out now. Not to mention, almost all nicely written frameworks or libraries or software in general now follow SemVer. Please read more about it.

As a PHP developer, composer is something we can't do without these days. If you think you are a PHP developer and haven't started using composer yet, you are not a PHP developer DOT In that case, search on Google on what it is and its tutorials or see its official documentation. In short, it is package manager for PHP that has superseded older methods such as PEAR, etc. It is like NPM for NodeJS or RubyGem for Ruby developers.

Let's say I want to install Symfony via composer, I can specify specific version to use in quite some ways like:

+--------------------------------+----------------------------------------------------------------+ | Version | Description | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "2.6.6" | Exact 2.6.6 version | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "\>= 2.6" | Any version greater than or equal to 2.6 like 2.6.7, 6.6.9 | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "\>= 2.6,\<3.0" | Any version greater than or equal to 2.6 but less than 3 Major | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "2.\*" | Any version as long as Major version is 2 | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "\*" | Latest version | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "dev-master" | Latest version from "master" branch | +--------------------------------+----------------------------------------------------------------+ | symfony/symfony: "dev-testing" | Latest version from "testing" branch | +--------------------------------+----------------------------------------------------------------+

We can also use special tilde character ~:

+---------------------------+-----------------------------------------------------------------------+ | Version | Description | +---------------------------+-----------------------------------------------------------------------+ | symfony/symfony: "~2.6.6" | Any version starting from 2.6.0 to 2.6.x with x being any number | +---------------------------+-----------------------------------------------------------------------+ | symfony/symfony: "~2.6" | Any version starting from 2.0 to 2.x or 2.x.x with x being any number | +---------------------------+-----------------------------------------------------------------------+ | symfony/symfony: "~2" | Any Major version greater than or equal to 2 like 2.x or 5.x.x | +---------------------------+-----------------------------------------------------------------------+

Once you know how to specify versions in composer, you can easily make sure you are only installing those packages that are backwards-compatible unless you want fresh installation of some package. Similarly, if you have wrote some package, you should choose versioning sensibly so that users of your package don't go incompatible accidentally if you have not made Major changes to your package.


By the way, here is extremely useful Composer cheat sheet, have fun !

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay