In PHP, what is the purpose of the __construct method in a class?
Correct answer
B. To initialize class properties
16 views
B. To initialize class properties
16 views
__construct() is the constructor: PHP calls it automatically when an object is created with new, and its job is to initialise the object's properties and perform any setup.
It does not create the instance — new does that — and clean-up is the role of __destruct().
Keep preparing with more Computer Science MCQs on MCQsExam.com.
Not sure why the answer is B? Ask here and get an explanation.