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/wpBlock.php

    r51568 r51657  
    276276            'core/dynamic',
    277277            array(
    278                 'render_callback' => function() {
     278                'render_callback' => static function() {
    279279                    return 'b';
    280280                },
     
    297297            'core/greeting',
    298298            array(
    299                 'render_callback' => function( $attributes, $content, $block ) {
     299                'render_callback' => static function( $attributes, $content, $block ) {
    300300                    return sprintf( 'Hello from %s', $block->name );
    301301                },
     
    367367                    ),
    368368                ),
    369                 'render_callback' => function( $block_attributes ) {
     369                'render_callback' => static function( $block_attributes ) {
    370370                    return sprintf(
    371371                        'Hello %s%s',
     
    392392            'core/outer',
    393393            array(
    394                 'render_callback' => function( $block_attributes, $content ) {
     394                'render_callback' => static function( $block_attributes, $content ) {
    395395                    return $content;
    396396                },
     
    400400            'core/inner',
    401401            array(
    402                 'render_callback' => function() {
     402                'render_callback' => static function() {
    403403                    return 'b';
    404404                },
Note: See TracChangeset for help on using the changeset viewer.