Recall & Review
beginner
What does the
instanceof operator do in PHP?It checks if an object is an instance of a specific class or implements a specific interface.Click to reveal answer
beginner
How do you use
instanceof to check if $obj is an instance of class Car?Use <code>$obj instanceof Car</code>. It returns <code>true</code> if <code>$obj</code> is a Car or subclass of Car, otherwise <code>false</code>.Click to reveal answer
intermediate
Can
instanceof check if an object implements an interface?Yes. It returns
true if the object implements the interface, otherwise false.Click to reveal answer
beginner
What will
instanceof return if the variable is not an object?It returns
false because instanceof only works with objects.Click to reveal answer
intermediate
Explain why
instanceof is useful in PHP programming.It helps to safely check an object's type before calling methods or accessing properties, preventing errors.
Click to reveal answer
What does
$obj instanceof ClassName return if $obj is an instance of a subclass of ClassName?✗ Incorrect
instanceof returns true if the object is an instance of the class or any subclass.Which of the following is true about
instanceof in PHP?✗ Incorrect
instanceof checks object type or interface implementation, not primitive types or strings.What will
instanceof return if the variable is null?✗ Incorrect
null is not an object, so instanceof returns false.If
$obj instanceof InterfaceName returns true, what does it mean?✗ Incorrect
instanceof confirms the object implements the interface.Which of these is a correct use of
instanceof?✗ Incorrect
The correct syntax is
$obj instanceof ClassName.Describe how the
instanceof operator works in PHP and give an example.Think about checking an object's type before using it.
You got /4 concepts.
Explain why using
instanceof can help prevent errors in PHP programs.Consider what happens if you call a method on a variable that is not an object.
You got /4 concepts.