Negative Squares
<?php
echo -3 ** 2;
// -9
This is still my favorite PHP bug : literal negative value is squared, and is … negative. In fact, the ** operator has precedence over the minus operator, and the square is then executed before the negation. Hence, the negative results. It is useful to process, correctly, parenthesises, but not integers.
See Also
- Operator Precedence
- -3 ^ 2 == -9 [Try me]
PHP Features
Last updated: 10 September 2026