Bird
0
0

Which of the following is the correct syntax to declare a destructor method in PHP?

easy📝 Syntax Q12 of 15
PHP - Classes and Objects
Which of the following is the correct syntax to declare a destructor method in PHP?
Afunction __destruct() {}
Bfunction destruct() {}
Cfunction _destruct() {}
Dfunction __destroy() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP destructor naming

    PHP destructor methods must be named exactly __destruct with two underscores.
  2. Step 2: Check syntax correctness

    The correct syntax is function __destruct() {}. Other options have incorrect names.
  3. Final Answer:

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

    Destructor syntax = __destruct() [OK]
Quick Trick: Destructor always starts with double underscores __destruct [OK]
Common Mistakes:
  • Using single underscore or wrong method name
  • Omitting parentheses in method declaration
  • Confusing with __construct method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes