The difference between the composer and the phrase between | and ||

What is the difference between pipe and douoble pipe in composer.json file? For instance:

"^1.0.0 || ^2.0.0" 

and

 '^1.0.0|^2.0.0' 
+6
source share
3 answers

They are the same.

If you look in the VersionParser class ( https://github.com/composer/semver/blob/1dd67fe56c0587d0d119947061a6bfc9863c101c/src/VersionParser.php#L237 ), you can see the following code:

 $orConstraints = preg_split('{\s*\|\|?\s*}', trim($constraints)); 

As we see in regular expression, are they? after the second pipe, making it optional.

Only the dual channel seems to be documented. ( https://getcomposer.org/doc/articles/versions.md#range )

+8
source

The difference is that | (single pipe) bitwise and and || (dual channel) logical or || is a logical OR operator. It looks like you basically know what it is. It is used in conditional statements such as if, while, etc.

 condition1 || condition2 

"||" will check the sequence starting from the first. If any condition in the sequence is true, then || stops further verification. more efficient in conditional statements

| is a bitwise OR operator. It was used for two numbers. You look at each bit of each number separately, and if one of the bits is 1, at least one of the numbers, then the resulting bit will be 1. Here are a few examples:

 A = 01010101 B = 10101010 A | B = 11111111 A = 00000001 B = 00010000 A | B = 00010001 
+1
source

I think this is the old syntax of a composer or logical operator. I found this link: http://qpleple.com/understand-composer-versions (search for channel symbol)

The introduction says:

Here are some excerpts from the Composer documentation refactored to better understand how package versions work and stability

but I could not find the link in the current documentation of the composer, then I assume that this is from an old version of the documents

+1
source

Source: https://habr.com/ru/post/1014619/