You are here: Re: Constructor as a "Reset" Button « PHP Programming Language « IT news, forums, messages
Re: Constructor as a "Reset" Button

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация