Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

PHP Features

Last updated: 10 September 2026