1.2.1320. Use Basename Suffix

basename() is able to remove a file extension when it is provided as argument. The second argument is removed from the name of the file. Using basename() instead of substr() or else, makes the intention clear.

<?php

$path = 'phar:///path/to/file.php';

// Don't forget the .
$filename = basename($path, '.php');

// Too much work for this
$filename = substr(basename($path), 0, -4);

?>

See also basename.

1.2.1320.1. Connex PHP features

1.2.1320.1.1. Suggestions

  • Use basename(), remove more complex code based on substr() or str_replace()

1.2.1320.1.2. Specs

Short name

Structures/BasenameSuffix

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.5.1

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Examples

NextCloud, Dolibarr

Available in

Entreprise Edition, Exakat Cloud