Re: Re: _Construct question

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

 



That's not true, running with v. 5.2.1:

<?php
class A
{
    function A() {
        echo "works\n";
    }
}

$a = new A();
?>

Outputs:

works


On Mar 21, 2007, at 8:06 AM, itoctopus wrote:

They're basically the same thing, however, you can only use __construct in
PHP5.

--
itoctopus - http://www.itoctopus.com
"John Comerford" <johnc@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:46007391.6040509@xxxxxxxxxxxxxxxxxx
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

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


erik jones <erik@xxxxxxxxxx>
software developer
615-296-0838
emma(r)




[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