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 a unary arithmetic operator in PHP used to decrement the numeric value of a variable by exactly one. It modifies the variable in place and evaluates to either the original or the decremented value, depending on its placement relative to the operand.
The operator operates in two distinct modes based on syntax positioning:
1. Pre-decrement (--$variable)
The PHP engine subtracts 1 from the variable’s value, updates the variable in memory, and then returns the newly updated value to the evaluating expression.
2. Post-decrement ($variable--)
The PHP engine reads the variable’s current value and caches it, subtracts 1 from the variable in memory, and then returns the cached (original) value to the evaluating expression.
Type Coercion and Edge Cases
The-- operator applies specific type-handling rules when the operand is not a strict integer or float:
- Numeric Strings: Strings containing valid numeric values (e.g.,
"5") are implicitly cast to integers or floats before the decrement operation is applied. - Non-Numeric Strings: Unlike the increment operator (
++), which supports Perl-style string increments, the decrement operator does not affect the value of non-numeric strings. As of PHP 8.3, applying--to a non-numeric string emits anE_DEPRECATEDwarning (slated to become aTypeErrorin PHP 9.0). In older versions, the operation silently does nothing. - Booleans: Decrementing a boolean (
trueorfalse) has no effect on the variable’s value. However, as of PHP 8.3, performing this operation emits anE_DEPRECATEDwarning. - Null: Decrementing a
nullvalue has no effect, and the variable remainsnull. As of PHP 8.3, this operation emits anE_DEPRECATEDwarning. - Objects/Arrays: Applying the decrement operator to an array or an object that does not overload the operation will result in a
TypeError.
Master PHP with Deep Grasping Methodology!Learn More





