WordPress.org

Make WordPress Core

#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 23 months ago.
diff patch
20801.patch (42.0 KB) - added by hakre 23 months ago.
20801.3.diff (992 bytes) - added by iandunn 11 months ago.

Download all attachments as: .zip

Change History (11)

uuf642923 months ago

diff patch

comment:1 SergeyBiryukov23 months ago

  • Description modified (diff)

Related: ticket:18975:10

comment:2 hakre23 months 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.

Version 0, edited 23 months ago by hakre (next)

hakre23 months ago

comment:3 SergeyBiryukov11 months 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 11 months ago by SergeyBiryukov (previous) (diff)

comment:4 michelwppi11 months 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 nacin11 months ago

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

comment:6 iandunn11 months ago

  • Cc ian.dunn@… added

iandunn11 months ago

comment:7 iandunn11 months 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 SergeyBiryukov11 months 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.

Note: See TracTickets for help on using tickets.