_Construct question
| From: | John Comerford | Date: | Tue, 20 Mar 2007 23:51:45 +0000 |
| Subject: | _Construct question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-250953@lists.php.net to get a copy of this message | ||
Hi Folks,
I am still pretty new to PHP and I have a question regarding classes and using _construct. Up until now I have been creating my classes as follows:
class test1 {
var $name;
function test1($pName) {
$this->name = $pName;
}
}
So I when I create a new class I can assign 'name' by doing '$t1 = new test1("test1");'
As part of another thread I noticed the _construct function which (if I am correct) does more or less the same thing:
class test2 {
var $name;
function _construct($pName) {
$this->name = $pName;
}
}
I have fished around a bit and cannot find why one might be better than the other. The only thing I can think is that maybe you need to use _construct to be able to use "extends" ?
Is this the case ? What is the advantage/disadvantage of using _construct as opposed to using a function with the classname ?
Thanks,
JC