Return Int Not Bool

../_images/return_int_not_bool.png

There is a cute deprecation warning, when using a closure to sort an array: Deprecated: usort(): Returning ``bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero``.

And if this deprecation is ignored, the boolean is cast automatically to an integer. As PHP turns 0 to false, and everything else, including 1 and -1 to true, this leads to surprising sorting effect.

Just trust the deprecation notice.

See Also

PHP Error Messages

PHP Features