Welcome to the Treehouse Community
Looking to learn something new?
Can someone explain to me Constructor Method ?
Im not sure how the Constructor Method works as when you echo out your not applying or calling anything in to the Constructor Method ?
Pere Grau7,750 Points
As I understand, the code inside the constructor method in a class is called every time that you call a method of that class. I'll put an example:
Imagine that you have a class named ClassA with a constructor method and three other methods: method1, method2, and method3. Every time you call a method, the code inside the constructor will be executed before the code of that method itself. So, having this:
$class = new ClassA(); $class->method1();
It will first execute the code inside the constructor and then the code inside method1. Well, at least this is how I see it.
Hope it helps! Cheers!
Its making a instance of a object
For example, If you had a dog object, you would want to make a constructor to have him bark or his breed or color or something like that