Opened 10 years ago
Closed 10 years ago
#32480 closed enhancement (duplicate)
Add _doing_it_wrong method call to WP_Widget PHP4 style constructor
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Widgets | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
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)
Change History (13)
#3
follow-up:
↓ 4
@
10 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:
↓ 5
@
10 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 callingWP_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
@
10 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
@
10 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
Updating to remove testing line in default-widgets.php