Home Development Tools composer What is the difference between Composer's tilde symbol ~ and the power symbol ^

What is the difference between Composer's tilde symbol ~ and the power symbol ^

Aug 12, 2020 pm 01:16 PM
composer

The following tutorial column of composer will introduce to you the difference between Composer’s tilde symbol ~ and the power symbol ^. I hope it will be helpful to friends in need!

What is the difference between Composer's tilde symbol ~ and the power symbol ^

I have seen too many people writing version numbers randomly (in fact, it is much better now than before). The next version of 1.9.0 must be 2.0.0, 2.9 .0 The next version must be 3.0.0... Mainly because there was no standard naming of version numbers before, and everyone wrote according to their mood. Later, semantic versioning was promoted, and the situation of version number naming was improved, but there are still many people who don’t know what the three-segment version number means (will you die if you teach these specifications in various training schools...).

To put it simply (I am just moving it, the website mentioned above makes it clearer), the meaning of each segment of the three-segment version number is:

Large version. Small version. Patch version

Let’s talk about the most obvious patch version first. If your software or library has had some bugs fixed before, the patch version needs to be 1.

Let’s talk about the minor version number. If you add a new feature, such as an RPG game that automatically picks up things, or a new method in your code base, it will not cause compatibility issues (BC) if users upgrade your code base, so a small version No. 1.

Finally, if your software is completely refactored, or your code base is completely refactored so that users upgrading the new library will inevitably cause compatibility issues, then the major version number is 1.

Of course, there will be cases where bugs are modified and functions are added at the same time. In short, if the previous bit requires 1, the following bits must be cleared to zero in any case.

In fact, there is no need to be too strict about software for end users, because end users don’t care much about the version (except for the big version number..., so chrome-style version numbers appeared, and Firefox also followed suit. ...), but for library file authors, it is better to abide by the version number, because the version number you set provides very important information to library callers, and they need to use your version number to determine whether to avoid compatibility issues. .

To give a more classic example, although Symfony 2/3/4 are similar in use, because there are interface inconsistencies between these three versions, the major version number must be 1. If your library file has an interface change that makes it incompatible with previous versions, even if there is only one, you should change the major version number to 1.

And if you develop some projects using Symfony 3.0.x, even if you upgrade directly to 3.4.x, theoretically there is no problem at all.

After talking about the three-segment version number, let’s talk about a problem that troubles PHPer. What do the ^ symbols and ~ symbols that specify the version number in composer.json mean? What's the difference?

Before writing this blog, I actually searched on Baidu and wanted to know if there were many related articles and whether this article was worth writing. The search results show that someone has indeed summarized it. Although most of them only have one example:

~1.2.3 represents 1.2.3 <= version number< 1.3.0

^1.2.3 represents 1.2.3 <= version number< ; 2.0.0

Based on the above transfer content, I will add a little more, ~ means that the version number can only change the last paragraph (if it is ~x.y, the end is y, if it is ~x.y.z, the end is z), For example, in this case:

~1.2 is equal to >=1.2.0; <2.0.0

and the ^ symbol is related to the semantic versioning mentioned above. It means to try to use the latest version, but to ensure that no compatibility problems occur. In other words, in addition to the major version number, the minor version number and the patch version number can be changed.

But it seems that there is a very important detail that no one has mentioned yet. In semantic versioning, the version number starting with 0 is quite special, and because ^ strictly abides by the semantic versioning rules, the following will appear. Situation (earlier composer versions did not have this processing, but it was later corrected):

^0.3.0 is equal to>=0.3.0; <0.4.0

eh? Shouldn't it be <1.0.0?

The reason is that the rule of semantic versioning is that if the major version number starts with 0, it means that it is an unstable version (unstable). If it is in an unstable state, the minor version number is not allowed to be backward compatible! So if you want to specify a library starting with 0, you must pay attention:

~0.1 This way of writing is very dangerous, because ~0.1 is equal to >=0.1.0; <1.0.0, which may cause failure In the case of backward compatibility, the safer way to write it is

^0.1 (equal to >=0.1.0; <0.2.0)

The above is the detailed content of What is the difference between Composer's tilde symbol ~ and the power symbol ^. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

Using Dicr/Yii2-Google to integrate Google API in YII2 Using Dicr/Yii2-Google to integrate Google API in YII2 Apr 18, 2025 am 11:54 AM

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

How to view the version number of laravel? How to view the version number of laravel How to view the version number of laravel? How to view the version number of laravel Apr 18, 2025 pm 01:00 PM

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library Apr 18, 2025 am 11:36 AM

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

See all articles