701 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+4 more
UDTHEMES says

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

2064 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
chrismccoy says

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

?

ive seen people do both.

2064 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in 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.

1699 posts Building the Web.
  • Has been a beta tester for an Envato feature
  • Sells items exclusively on Envato Market
  • Has sold $250,000+ on Envato Market
  • Had an item featured on Envato Market
+8 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

2064 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in 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.

3436 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 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?

2064 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in 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.

1699 posts Building the Web.
  • Has been a beta tester for an Envato feature
  • Sells items exclusively on Envato Market
  • Has sold $250,000+ on Envato Market
  • Had an item featured on Envato Market
+8 more
ZoomIt says

I’m not supporting PHP4 .

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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by