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

    r51599 r51657  
    511511     */
    512512    public function test_filter_block_registration() {
    513         $filter_registration = function( $args, $name ) {
     513        $filter_registration = static function( $args, $name ) {
    514514            $args['attributes'] = array( $name => array( 'type' => 'boolean' ) );
    515515            return $args;
     
    529529     */
    530530    public function test_filter_block_registration_metadata() {
    531         $filter_metadata_registration = function( $metadata ) {
     531        $filter_metadata_registration = static function( $metadata ) {
    532532            $metadata['apiVersion'] = 3;
    533533            return $metadata;
     
    547547     */
    548548    public function test_filter_block_registration_metadata_settings() {
    549         $filter_metadata_registration = function( $settings, $metadata ) {
     549        $filter_metadata_registration = static function( $settings, $metadata ) {
    550550            $settings['api_version'] = $metadata['apiVersion'] + 1;
    551551            return $settings;
Note: See TracChangeset for help on using the changeset viewer.