1.2.944. PHP Overridden Function

It is possible to declare and use a function with the same name as a PHP native, in a namespace.

Within the declaration namespace, it is easy to confuse the local version and the global version, unless the function has been prefixed with \.

When a piece of code use overridden function, any newcomer may be confused by the usage of classic PHP native function in surprising situations.

It is recommended to avoid redeclare PHP native function in namespaces.

<?php

namespace A {
    use function A\dirname as split;

    function dirname($a, $b) { return __FUNCTION__; }

    echo dirname('/a/b/c');
    echo split('a', 'b');

    echo \dirname('/a/b/c');
}

?>

1.2.944.1. Suggestions

  • Change the name of the function, in its declaration and usage.

1.2.944.2. Specs

Short name

Php/OveriddenFunction

Rulesets

All, Appinfo, CE, IsExt, IsPHP, IsStub

Exakat since

1.7.6

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

function

Configurable by

php_core, php_extensions, stubs

Available in

Entreprise Edition, Community Edition, Exakat Cloud