WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 6 months ago

#20801 closed defect (bug) (fixed)

Deprecating PHP4-style constructors gracefully

Reported by: uuf6429 Owned by: SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.2
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

The class WP_Widget in wp-includes/widget.php makes use of PHP4-style constructor for compatibility with plugins (mostly).

I propose two changes here:

  • A direct call to the old constructor should trigger a deprecation notice
  • The PHP4-style constructor *must* be declared after __construct() otherwise, an E_STRICT regarding constructor re-declaration is thrown.

Please find a patch attached...

Attachments (3)

patch.txt (1.1 KB) - added by uuf6429 3 years ago.
diff patch
20801.patch (42.0 KB) - added by hakre 3 years ago.
20801.3.diff (992 bytes) - added by iandunn 2 years ago.

Download all attachments as: .zip

Change History (13)

@uuf64293 years ago

diff patch

comment:1 @SergeyBiryukov3 years ago

  • Description modified (diff)

Related: ticket:18975:10

comment:2 @hakre3 years ago

Related: #16768

These changes look similar to the ones I have in my patched wordpress. That fixes the E_STRICT error for me, too. I attach my changes merged with yours, I think this needs to be deprecated with the next point release (3.4.0).

Thank you for bringing that issue up, this change went a bit lost on my box.

This is a related test-case: http://codepad.viper-7.com/o9RHpF

Last edited 3 years ago by hakre (previous) (diff)

@hakre3 years ago

comment:3 @SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.6
  • Version changed from 3.3.2 to 3.2

Related: #24357. [24288] made the E_STRICT notice more prominent.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

comment:4 @michelwppi2 years ago

Cool - temporary I do the patch on my local latest 3.6 nighty built...( moving ph4 call after constructor ) - no annoying message from widget.php. (I also take opportunity to upgrade my oldest plugins using WP_Widget class) - Waiting the next 3.6 nighty built ;-)

M.

comment:5 @nacin2 years ago

Not sure I see the reason for deprecating right now. Fixing the E_STRICT sounds good.

comment:6 @iandunn2 years ago

  • Cc ian.dunn@… added

@iandunn2 years ago

comment:7 @iandunn2 years ago

20801.3.diff swaps the order of the constructors to avoid the E_STRICT notice, but doesn't deprecate the PHP4 one.

comment:8 @SergeyBiryukov2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 24296:

Move the PHP4 constructor below the PHP5 one to avoid E_STRICT message. props uuf6429, iandunn. fixes #20801.

comment:9 @dd326 months ago

#30899 was marked as a duplicate.

comment:10 @TJNowell6 months ago

Of note, https://wiki.php.net/rfc/remove_php4_constructors PHP 7 is considering the removal of the old style constructor

Note: See TracTickets for help on using tickets.