15

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

"^1.0.0 || ^2.0.0"

and

'^1.0.0|^2.0.0'
Shanu k k
  • 1,235
  • 2
  • 18
  • 43
Roman678
  • 161
  • 1
  • 3

2 Answers2

22

They're the same.

If you look into 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 can see in the regex, they're is a ? after the second pipe, making it optional.

It seems that only the double pipe is documented though. (https://getcomposer.org/doc/articles/versions.md#range)

Pierre-Yves
  • 443
  • 3
  • 9
  • The single pipe is deprecated but retained for backwards compatibility. Your preg_split reference is spot on. – Scriptonomy Oct 31 '17 at 18:21
  • 2
    This is also discussed in this issue [here](https://github.com/composer/composer/issues/6755). They removed the documentation for a single pipe but it still remains functional for backwards compatibility. – Mike Harrison Sep 08 '19 at 20:07
3

I thinks it´s the old syntax of the composer OR logical operator. I found this reference: http://qpleple.com/understand-composer-versions (search for the pipe character)

In the introduction it says:

Here are some extracts from Composer's documentation reorganized to better understand how package versions and stability work

but I couldn't found any reference in current composer documentation, then I assume this is from an old version of the docs

Gabriel
  • 161
  • 2
  • 3