How do you define a constructor in a PHP class?

  • 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 is instantiated from the class and allows you 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 *