Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jrfnl opened this issue Jul 16, 2018 · 0 comments
Open

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

jrfnl opened this issue Jul 16, 2018 · 0 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Jul 16, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant