This question already has an answer here:
I have been reading PHP conventions in OOP and come across the |
operator/symbol which I cannot find any information on. After trial and error testing in an enviroment, I found that if the parameter is not a data-type int then the variable to the right of the parameter is outputted.
For example, let's use a class like this:
class MyClass {
const FROM_DB = 1;
const PUBLIC_ONLY = 0;
public static function getSomething($input, $db = 0, $public = 1) {
return $input;
}
}
This use-case would return 1:
echo MyClass::getSomething( 'test' | MyClass::FROM_DB | MyClass::PUBLIC_ONLY );
This use-case would return 7:
echo MyClass::getSomething( 6 | MyClass::FROM_DB | MyClass::PUBLIC_ONLY );
Finally, this use-case would return 'test':
echo MyClass::getSomething( 'test' , MyClass::FROM_DB | MyClass::PUBLIC_ONLY );
I do not understand what the |
is doing in this? I found it here. Can anyone explain what this is called and how it is used correctly?
Thank's in advance, see it working here.
</div>