Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 9 years ago

#20801 closed defect (bug) (fixed)

Deprecating PHP4-style constructors gracefully

Reported by: uuf6429's profile uuf6429 Owned by: sergeybiryukov's profile 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 12 years ago.
diff patch
20801.patch (42.0 KB) - added by hakre 12 years ago.
20801.3.diff (992 bytes) - added by iandunn 11 years ago.

Download all attachments as: .zip

Change History (13)

@uuf6429
12 years ago

diff patch

#1 @SergeyBiryukov
12 years ago

  • Description modified (diff)

Related: ticket:18975:10

#2 @hakre
12 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 12 years ago by hakre (previous) (diff)

@hakre
12 years ago

#3 @SergeyBiryukov
11 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 11 years ago by SergeyBiryukov (previous) (diff)

#4 @michelwppi
11 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.

#5 @nacin
11 years ago

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

#6 @iandunn
11 years ago

  • Cc ian.dunn@… added

@iandunn
11 years ago

#7 @iandunn
11 years ago

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

#8 @SergeyBiryukov
11 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.

#9 @dd32
9 years ago

#30899 was marked as a duplicate.

#10 @TJNowell
9 years 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.