PHPCompatibility Code

PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore

Recommendation

We don't recommend addressing it if you don't have a robust automated test suite. This incompatibility doesn't prevent your application from functioning.

Should you decide to fix it, beware of methods being called using call_user_func, the method name being composed using concatenation, or any other case that might make the method references hard to detect automatically.

We have even observed an environment where an external Java application was reading the PHP tests and relied on the __test prefix. A change in that situation would have caused severe repercussions on the customer's pipeline, despite having no impact on the PHP code.

Before

class Validation
{
    function __existsUserName($userName)
    {
    }
}

$validation = new Validation();
foreach ($rules as $rule) {
    $functionName = '__' . $rule . 'UserName';
    call_user_func(array($validation, $functionName), array($userName));
}

After

class Validation
{
    function existsUserName($userName)
    {
    }
}

$validation = new Validation();
foreach ($rules as $rule) {
    $functionName = $rule . 'UserName';
    call_user_func(array($validation, $functionName), array($userName));
}