Opened 2 months ago
Closed 2 months ago
#64497 closed enhancement (fixed)
Code Modernization: Replace manual comparison logic with the spaceship operator <=>
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch |
| Focuses: | Cc: |
Description
Since WordPress has bumped its minimum supported PHP version to 7.4, we should take advantage of modern PHP features to clean up legacy comparison logic. This ticket proposes replacing manual "less than / greater than" ternary or if/else blocks with the spaceship operator <=>.
The spaceship operator was introduced in PHP 7.0. It performs three-way comparisons and returns -1, 0, or 1 accordingly. In many parts of the WordPress Core, we still use verbose logic that can be simplified.
<?php return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
<?php return $a <=> $b;
Change History (3)
This ticket was mentioned in PR #10717 on WordPress/wordpress-develop by @Soean.
2 months ago
#1
- Keywords has-patch added
Note: See
TracTickets for help on using
tickets.
Trac ticket: https://core.trac.wordpress.org/ticket/64497