Wednesday, November 12, 2008

PHP max integer value (and min also :))

My colleague was looking for how to obtain min int value in PHP.
One of the pages I found contained an article advised PHP_INT_MAX constant.

Seems ok at first sight, right?

NO!

The first thing cames to mind is - there must be PHP_INT_MIN constant (as there is a function in PHP for each coders breath - it's natural PHP way) - but there isn't!
More of that, article author suggests to calculate min value:
Note that the PHP_INT_MAX also determines the smallest negative number – just multiply it by -1 to get the PHP integer minimum.
And its not his fault. Its "best" PHP practices - +-1 in such big numbers - who really cares of that :)

Thats why I don't like PHP, and there is much more - why I hate it :)

P.S. PHP int min is of course: (-1 * PHP_INT_MAX ) - 1

1 comment: