Make WordPress Core

Opened 18 months ago

Closed 18 months ago

Last modified 14 months ago

#50899 closed defect (bug) (fixed)

PHP 8.0: change `create_function()` to closure

Reported by: jrf Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: trivial Version:
Component: Build/Test Tools Keywords: has-patch php8 has-unit-tests has-dev-note
Focuses: coding-standards Cc:


create_function() has been removed in PHP 8.

The only usage of create_function() left is in a test situation for a test which - due to the deprecation of create_function() - is being skipped on PHP >= 7.2.

I propose to change the use of create_function() to a closure and remove the test skipping on PHP >= 7.2.

While not optimal as the closure would need to use eval, this change _should_ work and shouldn't cause any real world issues as the logic is only used within the test suite.

Attachments (1)

50899-remove-create_function.patch (2.6 KB) - added by jrf 18 months ago.

Download all attachments as: .zip

Change History (8)

This ticket was mentioned in PR #470 on WordPress/wordpress-develop by jrfnl.

18 months ago

  • Keywords has-unit-tests added

create_function() has been removed in PHP 8.

While not optimal due to the usage of eval, this change _should_ work and shouldn't cause any real world issues as the logic is only used within the test suite.

Trac ticket:

#2 @SergeyBiryukov
18 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Just linking to some related changesets here: [41722], [41730].

And tickets: #37082, #40109, #41562.

#3 @SergeyBiryukov
18 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 48790:

Code Modernization: Change create_function() in phpunit/includes/plural-form-function.php to closure.

create_function() has been deprecated in PHP >= 7.2 and removed in PHP 8.

The only instance left in core was used in a test that was being skipped on PHP >= 7.2. This allows the test to run again.

Follow-up to [41722], [41730].

Props jrf.
Fixes #50899.

#4 @desrosj
17 months ago

  • Keywords needs-dev-note added

Adding needs-dev-note to call this out in the PHP 8 dev note.

#5 @jrf
17 months ago

@desrosj Not sure this actually needs to be mentioned as it is a WP Core dev only change to part of the unit tests suite. There is nothing about this which would impact userland code.

#6 @desrosj
17 months ago

@jrf My thinking here (and with a few other tickets marked needs-dev-note related to PHP 8) is not to necessarily call out this specific change in Core, but rather note that it is something developers need to be aware of in their projects for PHP 8 support.

There were several items in the PHP 7.4 note that were similar to this ticket. Using the keyword to remember to at least mention this item in the PHP 8 note.

#7 @daisyo
14 months ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.