Bird
0
0

What does the instanceof operator check in PHP?

easy📝 Conceptual Q1 of 15
PHP - Inheritance and Polymorphism
What does the instanceof operator check in PHP?
AIf an object is an instance of a specific class or its subclass
BIf a variable is equal to a class name
CIf a class exists in the current namespace
DIf a function belongs to a class
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of instanceof

    The operator checks the relationship between an object and a class.
  2. Step 2: Identify what it returns

    It returns true if the object is an instance of the class or any subclass.
  3. Final Answer:

    It checks if an object is an instance of a specific class or its subclass -> Option A
  4. Quick Check:

    instanceof checks object-class relation = C [OK]
Quick Trick: instanceof checks object type, not variable value [OK]
Common Mistakes:
  • Confusing instanceof with equality operator
  • Thinking instanceof checks class existence
  • Assuming instanceof works with strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes