Bird
0
0

What does the instanceof operator do in PHP?

easy📝 Conceptual Q11 of 15
PHP - Inheritance and Polymorphism
What does the instanceof operator do in PHP?
ACreates a new instance of a class
BChecks if an object is an instance of a specific class or its subclass
CDeletes an object from memory
DConverts an object to a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of instanceof

    The instanceof operator is used to check if a variable is an object of a certain class or subclass.
  2. Step 2: Differentiate from other operations

    It does not create, delete, or convert objects; it only checks their type.
  3. Final Answer:

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

    instanceof checks object type [OK]
Quick Trick: Remember: instanceof checks object type, not creation or deletion [OK]
Common Mistakes:
  • Confusing instanceof with object creation
  • Thinking instanceof deletes objects
  • Assuming instanceof converts objects to strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes