What is the usage of the magic methods __construct() and __destruct(). Are they always required?
Need a nice simple answer to this, it’s a little confusing.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
About
__construct(), it gives you the possibility to do some stuff with your newly created object and to overwrite the__construct()method of a parent class.So it might not be required (neither are), but if a class extends another class, it might be required to add for example a constructor to avoid the automatic calling of a parent constructor.