constructors
Moderator: General Moderators
constructors
I have defined a class, and the page loads and works just fine, but I didn't define a constructor. Obviously constructors aren't required to create an object. Well, let me rephrase that, user defined constructors aren't required? To create my object I simply called $home = new page(); Is that the constructor? If I don't specify a constructor in my class definition, what does the php vm use to create my object? Are constructors required for object instantiation or are they simply used to give your objects sensible starting values for the objects internal properties?
- protokol
- Forum Contributor
- Posts: 353
- Joined: Fri Jun 21, 2002 7:00 pm
- Location: Cleveland, OH
- Contact:
Re: constructors
Nope.rathlon wrote:Well, let me rephrase that, user defined constructors aren't required?
Yes, this will "construct" the new object.rathlon wrote:To create my object I simply called $home = new page(); Is that the constructor?
If no constructor is defined in the class, then no internal variables will be set unless you explicitly define their values:rathlon wrote:If I don't specify a constructor in my class definition, what does the php vm use to create my object?
var $my_variable = "Hello";
In this case, the constructor basically is just using those values.
They are not required. Yes, they are used to set starting values in the object. Also they can be used to call a function that you want called whenever you instantiate your object.rathlon wrote:Are constructors required for object instantiation or are they simply used to give your objects sensible starting values for the objects internal properties?