Observed this week...
-
@Keith's (post 37) handles /0 and various WTFery longhand... but because % has a higher precedence than + does, meaning x % x + 1 nets you (x % x) + 1 = 1 which isn't right. But nice longhand WTFery.
Hey, mine works brillantly!
For the following vars:
$vars = array(-50.1, -2.7, "-2.7", -2, -1.0, -0.1, 0, 0.1, 1, 2, 2.7, "2.7", 50.1);
Here are the outputs:
-
Seems you're right:
$ php -r "var_dump(1.5);" float(1.5) $ php -r "var_dump(intval(1.5));" int(1)
I've taking to blindly assuming that any PHP function where there is a standard C function of the same name they'll do the same thing.
intval(2e70) actually returns 0, while the C equivalent would return 2e70. Although I can't find a man page...
-
Curious because I was working with x % x + 1 myself and was hit by precedence every time. I see it works... right now I do not understand why in that case.
-
And this is why PHP is TRWTF.
-