• 14

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Composer.phar difference between | and ||

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

"^1.0.0 || ^2.0.0"



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)

  • 14
Reply Report
      • 1
    • This is also discussed in this issue here. They removed the documentation for a single pipe but it still remains functional for backwards compatibility.

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

  • 1
Reply Report

The difference is that the | (single pipe) is bitwise or and || (double pipe )is logical Or || is the logical OR operator. It sounds like you basically know what that is. It's used in conditional statements such as if, while, etc.

condition1 || condition2

"|| " will check in sequence starting from first. If any condition in sequence is found to be true then || stops further checking.so || is more efficient in conditional statements

| is the bitwise OR operator. It's used to operate on two numbers. You look at each bit of each number individually and, if one of the bits is 1 in at least one of the numbers, then the resulting bit will be 1 also. Here are a few examples:

A = 01010101
B = 10101010
A | B = 11111111

A = 00000001
B = 00010000
A | B = 00010001
  • 0
Reply Report
    • @Shanukk I understand how bitwise operators works, but I do not understand what is the difference in version constraints. Take a look on two examples ^1.5.0 | ^2.0.0 and ^1.5.0 || 2.0.0. ^1.5.0 can return only true or false, right? ^2.0.0 also can return only true or false, right? so, there is no difference between: bool | bool AND bool || bool. right? if yes, what is the difference? if no, what is the reason of two different operators in composer.phar?
      • 2
    • This answer simply does not apply. There is no such difference between these operators using them as composer version constraints.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions