Bird
0
0

Which of the following is TRUE about the __destruct method in PHP?

easy📝 Conceptual Q2 of 15
PHP - Classes and Objects
Which of the following is TRUE about the __destruct method in PHP?
AIt is called automatically when the script ends or object is destroyed.
BIt must be called manually to free resources.
CIt can take parameters like a normal method.
DIt returns a value to indicate success.
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature rules

    The __destruct method cannot take parameters and does not return a value.
  2. Step 2: Understand when destructor runs

    PHP calls the destructor automatically when the object is destroyed or the script ends.
  3. Final Answer:

    It is called automatically when the script ends or object is destroyed. -> Option A
  4. Quick Check:

    Destructor auto-called at script end = C [OK]
Quick Trick: Destructor has no parameters and no return value [OK]
Common Mistakes:
  • Trying to pass arguments to destructor
  • Expecting destructor to return a value
  • Manually calling destructor instead of relying on PHP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes