|
Posted by ZeldorBlat on 07/24/07 22:38
On Jul 24, 5:03 pm, Sanders Kaufman <bu...@kaufman.net> wrote:
> Michael Fesser wrote:
> > .oO(Sanders Kaufman)
> >> That's ONE use for the constructor.
>
> > It's the only use. As it's name suggests - it's used to create an object
> > (and a destructor is called while cleaning up, respectively). In PHP the
> > constructor is more or less just for initialization, in other languages
> > it's also used to allocate memory for the new object.
>
> That was funny.
> It took just two sentences for you to contradict yourself.
>
> You're somewhat correct when you say that it's "more or less just for
> initialization". It is indeed useful for MORE than just initializing
> the object. In fact, it's also pretty good at re-initializing the object.
>
So are you suggesting that you call the constructor from elsewhere in
the class (or even explicitly from outside the class)? That's just
poor form. The constructor should be used for one thing only:
constructing a new instance of a class.
If you want to "reset" the object, then you separate that out into its
own method and call it from the constructor -- similar to what you've
done with the Connect() method.
I'm firmly with Micha on this one.
Navigation:
[Reply to this message]
|