Make WordPress Core


Ignore:
Timestamp:
08/26/2021 12:57:08 PM (5 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-request.php

    r51577 r51657  
    476476                                'args' => array(
    477477                                        'failparam' => array(
    478                                                 'sanitize_callback' => function () {
     478                                                'sanitize_callback' => static function () {
    479479                                                        $error = new WP_Error( 'invalid', 'Invalid.' );
    480480                                                        $error->add( 'invalid', 'Super Invalid.' );
    … …  
    511511                                'args' => array(
    512512                                        'failparam' => array(
    513                                                 'sanitize_callback' => function () {
     513                                                'sanitize_callback' => static function () {
    514514                                                        return new WP_Error( 'invalid', 'Invalid.', 'mydata' );
    515515                                                },
    … …  
    739739                                'args' => array(
    740740                                        'failparam' => array(
    741                                                 'validate_callback' => function () {
     741                                                'validate_callback' => static function () {
    742742                                                        $error = new WP_Error( 'invalid', 'Invalid.' );
    743743                                                        $error->add( 'invalid', 'Super Invalid.' );
    … …  
    774774                                'args' => array(
    775775                                        'failparam' => array(
    776                                                 'validate_callback' => function () {
     776                                                'validate_callback' => static function () {
    777777                                                        return new WP_Error( 'invalid', 'Invalid.', 'mydata' );
    778778                                                },
Note: See TracChangeset for help on using the changeset viewer.