On 3/21/07, Chris <[EMAIL PROTECTED]> 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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php