Re: [PHP] _Construct question
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
[PHP] _Construct question
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
Re: [PHP] _Construct question
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
Re: [PHP] _Construct question
On Tue, March 20, 2007 6:51 pm, John Comerford wrote: 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) { It changed from PHP 4 to PHP 5 because of various issues. Check on http://php.net for PHP 5 Migration suggestions. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php