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/blocks/context.php

    r51568 r51657  
    116116                    'gutenberg/contextWithoutDefault',
    117117                ),
    118                 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
     118                'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
    119119                    $provided_context[] = $block->context;
    120120
     
    156156            array(
    157157                'uses_context'    => array( 'postId', 'postType' ),
    158                 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
     158                'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
    159159                    $provided_context[] = $block->context;
    160160
     
    189189            array(
    190190                'uses_context'    => array( 'example' ),
    191                 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
     191                'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
    192192                    $provided_context[] = $block->context;
    193193
     
    197197        );
    198198
    199         $filter_block_context = function( $context ) {
     199        $filter_block_context = static function( $context ) {
    200200            $context['example'] = 'ok';
    201201            return $context;
Note: See TracChangeset for help on using the changeset viewer.