Loading video...
Object Constructors
- A constructor is a special object method that gets called automatically each time a new instance of a class is instantiated.
- Constructors are used to perform any initialization tasks that need to be done before an object is ready to be used, such as providing default values for all of an object’s properties.
- In PHP 5, constructors are known as magic methods and must be named
__construct(). They are defined within a class definition just like any other object method. - Arguments are provided to an object’s constructor method by specifying them between the parentheses
following the class name when an object is created using the
newkeyword:$person1 = new Person(‘Joe’, ‘Smith’);
- A class is not required to have a constructor method.
- Unlike other programming languages, only one constructor method can be defined per PHP class.
- Additional Resources:
Object Constructors
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview