1.2.1360. Use str_starts_with()

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

<?php

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

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

?>

See also str_ends_with().

1.2.1360.1. Suggestions

  • Use the native PHP function

1.2.1360.2. Specs

Short name

Structures/UseStrStartsWith

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