When you create your own custom widget, do you use
function Widget_Name
or do you use __construct, whats the difference between them both?
class Custom_Widget extends WP_Widget {
//function Custom_Widget() {
function __construct() {
I wouldn’t worry about it Chris. I personally would choose function Widget_Name
I use __construct() because it’s proper PHP coding 
However, there are no differences between __construct and just using the name of your class.
and what about parent::WP_Widget and $this->WP_Widget
?
ive seen people do both.
chrismccoy said
and what about parent::WP_Widget and $this->WP_Widget?
ive seen people do both.
This http://php.net/manual/en/keyword.parent.php explains it well.
If you extend a class, the class you’re extending becomes the parent. $this (or self:: if it’s a static class) means the class you’re using it in.
- Microlancer Beta Tester
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 50 and 99 items
- Exclusive Author
- Has been a member for 3-4 years
- Item was Featured
- Sold between 100 000 and 250 000 dollars
LandonWilson said
However, there are no differences between __construct and just using the name of your class.
PHP4 -> constructor function name = name of the class
PHP5 -> constructor function name = __construct
ZoomIt said
LandonWilson said
However, there are no differences between __construct and just using the name of your class.PHP4 -> constructor function name = name of the class
PHP5 -> constructor function name = __construct
I don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.
LandonWilson said
ZoomIt saidI don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.
LandonWilson said
However, there are no differences between __construct and just using the name of your class.PHP4 -> constructor function name = name of the class
PHP5 -> constructor function name = __construct
php4 isn’t support by WordPress anymore so why support it in themes?
OrganicBeeMedia said
LandonWilson saidphp4 isn’t support by WordPress anymore so why support it in themes?
ZoomIt saidI don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.
LandonWilson said
However, there are no differences between __construct and just using the name of your class.PHP4 -> constructor function name = name of the class
PHP5 -> constructor function name = __construct
Well, someone could be using an old version of WordPress, but I’d rather white those people out and tell them to upgrade rather than give myself a back ache.
- Microlancer Beta Tester
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 50 and 99 items
- Exclusive Author
- Has been a member for 3-4 years
- Item was Featured
- Sold between 100 000 and 250 000 dollars
I’m not supporting PHP4 .
I’m just pointing out the difference because that was the topic 
