nerdexam
National_Instruments

200-500 · Question #219

What is the output of the following script? 1 <?php 2 class a 3 { 4 public $val; 5 } 7 function renderVal (a $a) 8 { 9 if ($a) { 10 echo $a->val; 11 } 12 } 14 renderVal (null); 15 ?>

The correct answer is B. An error, because null is not an instance of 'a'. See the full explanation below for the reasoning.

Question

What is the output of the following script? 1 <?php 2 class a 3 { 4 public $val; 5 } 7 function renderVal (a $a) 8 { 9 if ($a) { 10 echo $a->val; 11 } 12 } 14 renderVal (null); 15 ?>

Options

  • AA syntax error in the function declaration line
  • BAn error, because null is not an instance of 'a'
  • CNothing, because a null value is being passed to renderVal()
  • DNULL

How the community answered

(28 responses)
  • A
    11% (3)
  • B
    79% (22)
  • C
    7% (2)
  • D
    4% (1)

Community Discussion

No community discussion yet for this question.

Full 200-500 Practice