[wp-trac] [WordPress Trac] #64497: Code Modernization: Replace manual comparison logic with the spaceship operator <=>
WordPress Trac
noreply at wordpress.org
Mon Jan 12 10:46:24 UTC 2026
#64497: Code Modernization: Replace manual comparison logic with the spaceship
operator <=>
-------------------------+-----------------------------
Reporter: Soean | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
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
[[https://www.php.net/manual/en/migration70.new-features.php#migration70
.new-features.spaceship-op|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
<?php
return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
}}}
{{{#!php
<?php
return $a <=> $b;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64497>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list