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 in PHP functions as both a binary arithmetic subtraction operator and a unary arithmetic negation operator, depending on its arity. It evaluates numeric expressions and applies PHP’s standard type juggling rules to non-numeric operands.
Binary Subtraction
When used with two operands,- calculates the difference by subtracting the right operand from the left operand.
- Returns an
intif both operands evaluate to integers and the resulting value does not exceed the bounds ofPHP_INT_MAXorPHP_INT_MIN. - Returns a
floatif either operand is a float, or if the subtraction results in an integer overflow or underflow.
Unary Negation
When used with a single operand,- inverts the algebraic sign of the value. Positive values become negative, and negative values become positive.
Type Coercion and Strictness
PHP dynamically coerces scalar types during the evaluation of the- operator. In modern PHP (8.0+), strict type validation applies to non-numeric values:
- Numeric Strings: Automatically cast to
intorfloatbased on the string’s format. - Booleans:
trueis cast to1;falseis cast to0. - Null: Silently evaluates to
0. - Non-Numeric Strings: Throws a
TypeError. - Arrays and Objects: Throws a
TypeError.
Precedence and Associativity
The PHP parser handles the- operator differently based on its context:
- Unary
-: Shares the exact same precedence level as increment (++), decrement (--), and type casting operators. Unary-is right-associative, meaning chained unary operators evaluate strictly from right to left. - Binary
-: Shares precedence with addition (+). As of PHP 8.0, it has strictly higher precedence than string concatenation (.). Binary-is left-associative, meaning chained expressions are evaluated strictly from left to right.
Master PHP with Deep Grasping Methodology!Learn More





