TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
|= operator is the bitwise OR assignment operator in PHP. It performs a bitwise OR operation between the binary representations of the left and right operands, and immediately assigns the resulting integer or string value back to the left operand.
Syntax
Bitwise Mechanics
When the|= operator is invoked, PHP evaluates the operands at the bit level. For each corresponding bit position in the two operands, the operator applies the following truth table:
0 | 0yields00 | 1yields11 | 0yields11 | 1yields1
1, the resulting bit is 1. The bit is 0 only if both corresponding bits are 0.
Evaluation Example
Type Handling and Coercion
The behavior of the|= operator depends strictly on the data types of the operands provided:
- Integers: The standard bitwise operation is performed on the binary integer values.
- Floats: If either operand is a floating-point number, PHP truncates the fractional part, casting the float to an integer before performing the bitwise operation. As of PHP 8.1, performing this implicit conversion on a float with a fractional part emits a deprecation notice (
Implicit conversion from float to int loses precision). - Strings (Both Operands): If both the left and right operands are strings, the
|=operator performs the bitwise OR operation on the underlying ASCII values of the characters at each corresponding byte position. The length of the resulting string will match the length of the longer string operand. - Mixed Types: In PHP 8.0 and later, attempting a bitwise operation between an integer or float and a completely non-numeric string, or a string with trailing non-numeric characters (e.g.,
"10 foo"), throws a fatalTypeError(Unsupported operand types: int | string). Strings must be strictly numeric to be implicitly cast to integers during mixed-type bitwise operations.
Master PHP with Deep Grasping Methodology!Learn More





