So I see __construct being used in the PHP sources. I've recently picked up on using OOP in PHP, and I've been doing
class Whatever {
function Whatever() { /* shit to do on call */ }
}
What is the difference? Is one processed faster? Or what?
Results 1 to 4 of 4
Thread: PHP classes, __construct
- 17 Nov. 2009 05:56am #1
PHP classes, __construct
- 18 Nov. 2009 07:02am #2
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00
__cunstruct is executed on the creation of the class.
Example;
$Class = new Class($Variable);
That input would be used for the __cunstruct function.
__destruct happens when the PHP processing is about to output the final web page.
I use it to either display errors, or unset all variables.
- 18 Nov. 2009 07:20am #3
If you name a function the same as the class name, it executes on the creation of the class as well.
e.g.
class test {
function __construct() { echo 'hello, world'; }
}
and
class test {
function test() { echo 'hello, world'; }
}
are synonymous.
I was just wondering if one was faster than the other, or if one was standard, or what.
- 18 Nov. 2009 07:22am #4
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00