Re: _Construct question

From: Date: Wed, 21 Mar 2007 00:09:35 +0000
Subject: Re: _Construct question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-250954@lists.php.net to get a copy of this message
John Comerford wrote:
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; } }
It's __construct (double underscore). PHP5 uses __construct PHP4 uses the class name. To support both: class test { // php5 calls this function __construct() { echo 'do stuff here'; } // php4 calls this function test() {
    $this->__construct();
} } :D -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#250954) next »