Bird
0
0

Identify the error in this PHP class:

medium📝 Debug Q6 of 15
PHP - Classes and Objects
Identify the error in this PHP class:
class Demo {
  function __destruct($msg) {
    echo $msg;
  }
}
ADestructor must be declared static.
BDestructor must return a value.
CDestructor cannot have parameters.
DDestructor name should be destruct without underscores.
Step-by-Step Solution
Solution:
  1. Step 1: Check destructor method signature

    PHP destructor __destruct cannot accept any parameters.
  2. Step 2: Identify error in code

    The code declares __destruct($msg) with a parameter, which is invalid and causes a syntax error.
  3. Final Answer:

    Destructor cannot have parameters. -> Option C
  4. Quick Check:

    Destructor parameters not allowed = D [OK]
Quick Trick: Destructor method must have empty parentheses [OK]
Common Mistakes:
  • Adding parameters to destructor
  • Expecting destructor to return a value
  • Using wrong method name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes