Zend
200-710 · Question #90
What is the output of the following code? class a { public $val; function renderVal (a $a) { if ($a) { echo $a->val; } } renderVal (null);
The correct answer is B. An error, because null is not an instance of 'a'. See the full explanation below for the reasoning.
Object-Oriented Programming
Question
What is the output of the following code?
class a
{
public $val;
function renderVal (a $a)
{
if ($a) {
echo $a->val;
}
}
renderVal (null);
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
(47 responses)- A2% (1)
- B81% (38)
- C4% (2)
- D13% (6)
Topics
#type hinting#null argument#class type hints#strict typing
Community Discussion
No community discussion yet for this question.