Make WordPress Core

Changeset 52322


Ignore:
Timestamp:
12/04/2021 05:18:48 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Break the $path reference after a foreach loop in block_editor_rest_api_preload().

When using a foreach loop with a value assigned by reference, the variable continues to point to the last array element even after the loop, so it is recommended to destroy it by unset() to avoid unexpected behavior later on.

See PHP Manual: foreach.

Follow-up to [52312], [52313].

Props TobiasBg.
See #54558.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r52312 r52322  
    8484     */
    8585    $block_categories = apply_filters( 'block_categories_all', $block_categories, $block_editor_context );
     86
    8687    if ( ! empty( $block_editor_context->post ) ) {
    8788        $post = $block_editor_context->post;
     
    124125     */
    125126    $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $block_editor_context );
     127
    126128    if ( ! empty( $block_editor_context->post ) ) {
    127129        $post = $block_editor_context->post;
     
    398400     */
    399401    $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $block_editor_context );
     402
    400403    if ( ! empty( $block_editor_context->post ) ) {
    401404        $post = $block_editor_context->post;
     
    441444     */
    442445    $preload_paths = apply_filters( 'block_editor_rest_api_preload_paths', $preload_paths, $block_editor_context );
     446
    443447    if ( ! empty( $block_editor_context->post ) ) {
    444448        $selected_post = $block_editor_context->post;
     
    479483        }
    480484    }
     485
     486    unset( $path );
    481487
    482488    $preload_data = array_reduce(
Note: See TracChangeset for help on using the changeset viewer.