Bird
0
0

Which statement about the instanceof operator is FALSE?

hard📝 Conceptual Q10 of 15
PHP - Inheritance and Polymorphism
Which statement about the instanceof operator is FALSE?
A<code>instanceof</code> returns false if the variable is null
B<code>instanceof</code> can check if a class exists in the current namespace
C<code>instanceof</code> throws a fatal error if used on a non-object variable
D<code>instanceof</code> can be used to check if an object is an instance of a parent class
Step-by-Step Solution
Solution:
  1. Step 1: Review instanceof behavior with null and non-objects

    instanceof returns false for null and throws error for non-objects.
  2. Step 2: Check class existence check

    instanceof does NOT check if a class exists; use class_exists() instead.
  3. Final Answer:

    instanceof can check if a class exists in the current namespace is FALSE -> Option B
  4. Quick Check:

    instanceof does not check class existence = D [OK]
Quick Trick: Use class_exists() to check class presence, not instanceof [OK]
Common Mistakes:
  • Thinking instanceof checks class existence
  • Ignoring error on non-object variables
  • Assuming instanceof returns true for null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes