Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Variables and Data Types
What will be the output of this PHP code?
$a = 9223372036854775807;
$b = $a + 1;
echo gettype($b);
A"boolean"
B"integer"
C"string"
D"double"
Step-by-Step Solution
Solution:
  1. Step 1: Understand integer overflow in PHP

    When exceeding the platform's max integer size, adding causes overflow and converts to double.
  2. Step 2: Analyze the code

    $a is max 64-bit signed int. $b = $a + 1 causes overflow, so $b becomes double. gettype($b) returns "double".
  3. Final Answer:

    "double" -> Option D
  4. Quick Check:

    Integer overflow converts to float = "double" [OK]
Quick Trick: Integer overflow in PHP converts to float automatically. [OK]
Common Mistakes:
  • Expecting integer type after overflow
  • Confusing float with string
  • Ignoring system architecture effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes