Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#64488 closed enhancement (fixed)

Code Modernization: replace if isset() return with null coalescing

Reported by: Soean Owned by: westonruter
Priority: normal Milestone: 7.0
Component: General Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses: coding-standards

Description (last modified by westonruter)

In #63430 isset() ternary were replaced with null coalescing.

We also should replace if isset() return with null coalescing.

<?php
-        if (isset($this->items[$key])) {
-            return $this->items[$key];
-        }
-
-        return 'fallback value';
+        return $this->items[$key] ?? 'fallback value';

This is part of #58874.

Change History (7)

This ticket was mentioned in PR #10703 on WordPress/wordpress-develop by @Soean.


7 months ago
#1

  • Keywords has-patch added

#2 @sabernhardt
7 months ago

  • Summary Coding Standards: replace if isset() return with null coalescingCode Modernization: replace if isset() return with null coalescing
  • Type defect (bug)enhancement

#3 @westonruter
7 months ago

  • Milestone Awaiting Review7.0
  • Owner set to westonruter
  • Status newreviewing

#4 @westonruter
7 months ago

  • Description modified (diff)

@westonruter commented on PR #10703:


7 months ago
#5

@Soean I found some additional opportunities in de042b59f67db0d6014be62bbe83070962ce8ad1. Take a look.

#6 @mukesh27
7 months ago

  • Keywords commit added

Mark ready for commit.

@westonruter will commit this soon.

#7 @westonruter
7 months ago

  • Resolutionfixed
  • Status reviewingclosed

In 61470:

Code Modernization: Replace if statements with null coalescing operator.

Developed in https://github.com/WordPress/wordpress-develop/pull/10703

Follow-up to [61464], [61463], [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

Props soean, westonruter, mukesh27.
See #58874.
Fixes #64488.

Note: See TracTickets for help on using tickets.