1. Home
  2. Computer Science MCQs
  3. PHP
  4. In PHP, what is the purpose of the __construct method in a…

Added 23 Jan 2024

In PHP, what is the purpose of the __construct method in a class?

  1. To create a new instance of the class
  2. To initialize class properties Correct answer
  3. To destroy the class object
  4. To update class methods

Correct answer

B. To initialize class properties

16 views

MCQSEXAM

Explanation

__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.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs