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/actions/closures.php

    r46586 r51657  
    1313    function test_action_closure() {
    1414        $tag     = 'test_action_closure';
    15         $closure = function( $a, $b ) {
     15        $closure = static function( $a, $b ) {
    1616            $GLOBALS[ $a ] = $b;
    1717        };
     
    2626
    2727        $tag2     = 'test_action_closure_2';
    28         $closure2 = function() {
     28        $closure2 = static function() {
    2929            $GLOBALS['closure_no_args'] = true;
    3030        };
Note: See TracChangeset for help on using the changeset viewer.