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?
Printable View
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?
__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.
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.