Page 1 of 1

$this->object->do();

Posted: Sun Aug 14, 2005 3:20 pm
by Ree

Code: Select all

$this->object->doSomething();
Is this kind of expression all right? I used this in a constructor of one of my classes. The class needs to use my database class to access/modify data in the db, so I used

Code: Select all

$this->db->new Database(db_host, db_name, db_user, db_pass);
$this->db->Connect();
in the class' constructor, which enabled me to use the same connection while using different functions instead of recreating the db object every time in those functions. The thing did work, but still, do you find this normal or should I rethink something?

Re: $this->object->do();

Posted: Sun Aug 14, 2005 8:01 pm
by harrisonad
Yes, this is ok.

But I think you didn't recognized the syntax of you post.

Code: Select all

$this->db = new Database(db_host, db_name, db_user, db_pass);
$this->db->Connect();
I changed -> to = on line 1

Posted: Mon Aug 15, 2005 1:52 am
by Ree
Oh yes, that was my mistake. Thanks

Posted: Mon Aug 15, 2005 3:06 am
by patrikG

Code: Select all

$this->classFunction->doWhatever()
is called composition, a commonly used OO-technique. It's counterpart is aggregation (see same article).