Bird
0
0

How do you properly define a destructor method in a PHP class?

easy📝 Syntax Q3 of 15
PHP - Classes and Objects
How do you properly define a destructor method in a PHP class?
Afunction destruct() {}
Bfunction __destruct() {}
Cfunction _destruct() {}
Dfunction __destructor() {}
Step-by-Step Solution
Solution:
  1. Step 1: Understand PHP destructor naming

    PHP uses the magic method named __destruct with two underscores.
  2. Step 2: Check syntax

    The destructor must be declared as function __destruct() without parameters.
  3. Final Answer:

    function __destruct() {} -> Option B
  4. Quick Check:

    Correct magic method name with double underscores [OK]
Quick Trick: Destructor method is always named __destruct() with two underscores [OK]
Common Mistakes:
  • Using single underscore instead of double underscores
  • Naming the method destruct() without underscores
  • Adding parameters to the destructor method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes