Re: _Construct question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux