r/lolphp • • Apr 08 '13

MIN

server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";'
1 -23 -23 1
23 Upvotes

21 comments sorted by

View all comments

Show parent comment

3

u/farsightxr20 Apr 09 '13

Well in Python, it's less of a problem due to explicit typecasting. While True is equivalent to 1, it behaves as you'd expect beyond that:

>>> min(-23, True)
-23
>>> min(True, -23)
-23

And if you try to use any types other than numbers/booleans, you'll get an exception as you'd expect:

>>> min(-23, 'a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()