1.2.1359. Use str_ends_with()

There is a dedicated function to check the suffix of a string : it is called str_ends_with(). It is available since PHP 8.0

<?php

if (str_ends_with($a, 'abc')) { }

// Before PHP 8.2
if (substr($a, -3) === 'abc') { }

?>

See also str_ends_with().

1.2.1359.1. Suggestions

  • Use the native PHP function

1.2.1359.2. Specs

Short name

Structures/UseStrEndsWith

Rulesets

All, Suggestions

Exakat since

2.5.2

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud