I pulled this result from here:
And interestingly, the result of
var_dump((int)(PHP_INT_MAX + 1))
will be displayed as a negative number (in the case of this specific example, it will displayint(-9223372036854775808)
). Again, the key here is for the candidate to know that the value will be displayed as a negative number.
Is the int negative because adding 1 will overflow the integer bits and change the bit representing the sign of the int? What's the reason?
@kainaw is right.
This is called "buffer overflow".
PHP handled it in the best way possible.
If PHP didn't make that integer positive, there would be an extra "bit" floating around in the RAM (probably causing a 502 error, but it could be much worse)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With