Skip to content

New sniff: change use of alias functions to use the master function #14

Description

@jrfnl
Sniff basics -
Fixable for PHP: various, depends on when the function(s) were introduced
Sniff type: Best Practice
Fixer type: Safe/Risky (depending on the function)

Short description

As a general best practice, it is recommended not to use alias functions.

Related PHPCompatibility sniff(s):

  • N/A

PHP manual references:

  • There are quite a few functions in PHP which you can call with more than one name. In some cases there is no preferred name among the multiple ones, is_int() and is_integer() are equally good for example. However there are functions which changed names because of an API cleanup or some other reason and the old names are only kept as aliases for backward compatibility. It is usually a bad idea to use these kind of aliases, as they may be bound to obsolescence or renaming, which will lead to unportable script. This list is provided to help those who want to upgrade their old scripts to newer syntax.

    http://php.net/manual/en/aliases.php

Example code:

Detect the following code pattern(s):

$str = chop( $str, "\t");
$a = doubleval($var);
if ( is_real ( $var ) ) {}
gzputs( $zp , $string, 1000 );

And fix these to:

$str = rtrim( $str, "\t");
$a = floatval($var);
if ( is_float ( $var ) ) {}
gzwrites( $zp , $string, 1000 );

Notes for implementation of the sniff:

  • An inventory of the PHP introduction version of all applicable original and alias functions will need to be created.
  • Function parameters will need to be carefully verified to be the same.

Prior art:

  • CS-fixer: no_alias_functions

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions