nerdexam
National_Instruments

200-500 · Question #145

What is the output of the following script? 1 <?php 2 function ratio ($x1 = 10, $x2) 3 { 4 if (isset ($x2)) { 5 return $x2 / $x1; 6 } 7 } 9 echo ratio (0); 10 ?>

The correct answer is D. A warning, because $x2 is not set. See the full explanation below for the reasoning.

Question

What is the output of the following script? 1 <?php 2 function ratio ($x1 = 10, $x2) 3 { 4 if (isset ($x2)) { 5 return $x2 / $x1; 6 } 7 } 9 echo ratio (0); 10 ?>

Options

  • A0
  • BAn integer overflow error
  • CA warning, because $x1 is not set
  • DA warning, because $x2 is not set
  • EA floating-point overflow error

How the community answered

(38 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    16% (6)
  • D
    71% (27)
  • E
    8% (3)

Community Discussion

No community discussion yet for this question.

Full 200-500 Practice