Re: _Construct question

From: Date: Wed, 21 Mar 2007 08:20:02 +0000
Subject: Re: _Construct question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-250987@lists.php.net to get a copy of this message
On 3/21/07, Chris <dmagick@gmail.com> wrote:
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 To support both, i wouldn't even think about the PHP5 __Construct. I
would just do it like this:
class test { function test() { echo 'do stuff here'; } }
Tijnema
-- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#250987) next »