Make WordPress Core


Ignore:
Timestamp:
08/26/2021 12:57:08 PM (3 years ago)
Author:
hellofromTonya
Message:

Coding Standards: Use static closures when not using $this.

When a closure does not use $this, it can be made static for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r51568 r51657  
    21382138    public function test_prepare_item_filters_content_when_needed() {
    21392139        $filter_count   = 0;
    2140         $filter_content = function() use ( &$filter_count ) {
     2140        $filter_content = static function() use ( &$filter_count ) {
    21412141            $filter_count++;
    21422142            return '<p>Filtered content.</p>';
     
    21742174    public function test_prepare_item_skips_content_filter_if_not_needed() {
    21752175        $filter_count   = 0;
    2176         $filter_content = function() use ( &$filter_count ) {
     2176        $filter_content = static function() use ( &$filter_count ) {
    21772177            $filter_count++;
    21782178            return '<p>Filtered content.</p>';
Note: See TracChangeset for help on using the changeset viewer.