NYCPHP Meetup

NYPHP.org

[nycphp-talk] Constructors and

csnyder chsnyder at gmail.com
Wed Oct 18 23:05:35 EDT 2006


On 10/18/06, Matthew Terenzio <matt at jobsforge.com> wrote:
> Just seems cumbersome to create a new object and ALWAYS
> follow with a given method.
> I thought that's what constructors were for.

I think it's good practice to keep actions out of the constructor. I
typically end up wanting to change configuration or set some
properties before I start calling methods on an object, maybe months
or years after writing the class.

$user = new User();
$user->useLDAP( $server, $domain );
$user->load( $username );

If the constructor starts doing stuff on instantiation, then you're
potentially cut off from flexibility down the line.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list