You are writing a PHP script and you need to define a constructor in a class. How would you do this?

  • Using the __construct() method
  • Using the init() method
  • Using the create() method
  • Using the constructor() method
In PHP, to define a constructor in a class, you would use the __construct() method. The correct option is "Using the __construct() method." This special method is automatically called when an object of the class is created. It is used to initialize the object's properties or perform other setup tasks. For further details, refer to the PHP documentation on constructors: http://php.net/manual/en/language.oop5.decon.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *