WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#32480 closed enhancement (duplicate)

Add _doing_it_wrong method call to WP_Widget PHP4 style constructor

Reported by: welcher Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

WP_Widget contains a PHP4 style constructor for backwards compatibility. As was noted in #20801 PHP7 is removing them - https://wiki.php.net/rfc/remove_php4_constructors.

WordPress still supports PHP 5.2 so removing them is not an option but I would like to introduce a _doing_it_wrong call if the the PHP4 style constructor is used to hopefully prompt the widget author to use __construct instead.

Attachments (2)

32480.diff (1.1 KB) - added by welcher 5 years ago.
32480.2.diff (564 bytes) - added by welcher 5 years ago.
Updating to remove testing line in default-widgets.php

Download all attachments as: .zip

Change History (13)

@welcher
5 years ago

#1 @welcher
5 years ago

  • Keywords has-patch dev-feedback added

@welcher
5 years ago

Updating to remove testing line in default-widgets.php

#2 @netweb
5 years ago

Related: #31982

#3 follow-up: @dd32
5 years ago

WordPress still supports PHP 5.2 so removing them is not an option

Minor clarification; Only PHP4 requires them, they're included for backwards compatibility with plugins who are subclassing WP_Widget and calling WP_Widget::WP_Widget() directly in their constructors.

#4 in reply to: ↑ 3 ; follow-up: @jdgrimes
5 years ago

Replying to dd32:

WordPress still supports PHP 5.2 so removing them is not an option

Minor clarification; Only PHP4 requires them, they're included for backwards compatibility with plugins who are subclassing WP_Widget and calling WP_Widget::WP_Widget() directly in their constructors.

This will continue to work for the foreseeable future of PHP (at least to PHP 8). I'm not saying we shouldn't deprecate these, I just want to clarify that calling parent::WP_Widget() in a child widget's constructor isn't going to be breaking in the future due to that RFC. It will still work as it does now.

What will break is if they are defining WP_Widget() method as their widget constructor instead of __construct(). In PHP 7 they will get an E_DEPRECATED error, and in PHP 8 it will cease to be a constructor.

#5 in reply to: ↑ 4 @welcher
5 years ago

Thanks for the clarifications!

I should have been more clear in my original statement. What I was meaning was that since WP supports versions of PHP that still support PHP4 style of constructors - we can't just remove them and the addition of a _doing_it_wrong call will hopefully prompt updating to the PHP5 syntax.

#6 @chriscct7
5 years ago

We could also consider emailing the plugin authors who use the PHP 4 constructors and ask them to update. We've got a list compiled of the slugs for all of the plugins on WordPress.org that are doing it

#7 @johnbillion
5 years ago

  • Version trunk deleted

#8 @welcher
4 years ago

Related tickets #32470, #23012.

This ticket was mentioned in Slack in #core by welcher. View the logs.


4 years ago

#10 @welcher
4 years ago

Now that [32990] has been committed - is this no longer relevant?

#11 @jorbin
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #31982.

Sorry, I had missed this ticket. Yes, it's no longer relevant.

Note: See TracTickets for help on using tickets.