701 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Canada
  • Collector Level 6
chrismccoy
says

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()  {
7 posts UnlimitDesign
  • 6 Years of Membership
  • Affiliate Level 6
  • Author Level 10
  • Collector Level 4
+5 more
UDTHEMES
says

I wouldn’t worry about it Chris. I personally would choose function Widget_Name

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says

I use __construct() because it’s proper PHP coding :)

However, there are no differences between __construct and just using the name of your class.

701 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Canada
  • Collector Level 6
chrismccoy
says

and what about parent::WP_Widget and $this->WP_Widget

?

ive seen people do both.

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says
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.

1744 posts Building the Web.
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Beta Tester
+10 more
ZoomIt
says
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

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says
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.

3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 more
organicbee
says
LandonWilson said
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.

php4 isn’t support by WordPress anymore so why support it in themes?

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says
OrganicBeeMedia said
LandonWilson said
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.
php4 isn’t support by WordPress anymore so why support it in themes?

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.

1744 posts Building the Web.
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Beta Tester
+10 more
ZoomIt
says

I’m not supporting PHP4 .

I’m just pointing out the difference because that was the topic :P

by
by
by
by
by
by