PHP Classes
elePHPant
Icontem

PHP Code Fixer: Find deprecated functions and variables in PHP

Recommend this page to a friend!
  Info   View files Example   View files View files (32)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-08-22 (29 days ago) RSS 2.0 feedStarStarStarStar 64%Total: 341 This week: 1All time: 6,782 This week: 624Up
Version License PHP version Categories
phpcodefixer 1.0.3MIT/X Consortium ...5PHP 5, Utilities and Tools, Parsers
Description Author

This package can find deprecated functions and variables in PHP.

It can parse PHP code and find known issues of functions, variables and php.ini configuration directives that are deprecated.

The package can also suggest replacements for the code that uses deprecated features.

Innovation Award
PHP Programming Innovation award nominee
March 2017
Number 2
Over time PHP deprecated and remove some of its functions and variables that were supported in past versions.

This package parse PHP code and find known issues of functions, variables and php.ini configuration directives that are deprecated. It can also suggest replacements for the code that uses deprecated features.

Manuel Lemos
  Performance   Level  
Name: Sergey Vanyushin is available for providing paid consulting. Contact Sergey Vanyushin .
Classes: 15 packages by
Country: Russian Federation Russian Federation
Age: 21
All time rank: 79729 in Russian Federation Russian Federation
Week rank: 19 Up3 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 14x

Winner: 1x

Details

PhpCodeFixer

Composer package Latest Stable Version Total Downloads License

PhpCodeFixer finds deprecated functions, wrong functions usage, variables, ini directives and restricted identifiers in your php code. It literally helps you fix code that can fail after migration to PHP 7.

  1. Usage
  2. Example
  3. Installation

Usage

To scan your files or folder launch phpcf and pass file or directory names.

Usage: phpcf [--target VERSION] [--max-size SIZE] FILES...

Options:
  -t, --target VERSION  target php version [default: 7.2]
  -s, --max-size SIZE   sets max size of php file. If size of file is above this value, file will be skipped [default: 1mb]

By providing additional parameter --target you can specify version of PHP to perform less checks.

| Option | Action | |--------------|---------------------------------------------| | --target 7.2 | By default. Use all deprecations up to 7.2. | | --target 7.1 | Use all deprecations from 5.3 to 7.1. | | --target 7.0 | Use all deprecations from 5.3 to 7.0. | | --target 5.6 | Use all deprecations from 5.3 to 5.6. | | --target 5.5 | Use all deprecations from 5.3 to 5.5. | | --target 5.4 | Use all deprecations from 5.3 to 5.4. | | --target 5.3 | Use deprecations from 5.3 only. |

Example of usage

> phpcf tests
Max file size set to: 1.000 MiB
Scanning tests ...
 PHP |             Type |                          File:Line | Issue
 5.3 | function         |                    tests/5.3.php:2 | Function dl() is deprecated.
 5.3 | ini              |                    tests/5.3.php:3 | Ini define_syslog_variables is deprecated.
 5.4 | function         |                    tests/5.4.php:2 | Function mcrypt_generic_end() is deprecated.
 5.4 | function         |                    tests/5.4.php:3 | Function magic_quotes_runtime() is deprecated.
 5.5 | function_usage   |                    tests/5.5.php:2 | Function usage preg_replace (@preg_replace_e_modifier) is deprecated.
 5.6 | ini              |                    tests/5.6.php:6 | Ini mbstring.http_output is deprecated.
 5.6 | variable         |                    tests/5.6.php:3 | Variable $HTTP_RAW_POST_DATA is deprecated.
 7.0 | function         |                    tests/7.0.php:8 | Function mssql_connect() is deprecated.
 7.0 | ini              |                   tests/7.0.php:10 | Ini always_populate_raw_post_data is deprecated.
 7.0 | function_usage   |                   tests/7.0.php:12 | Function usage password_hash (@password_hash_salt_option) is deprecated.
 7.0 | identifier       |                   tests/7.0.php:14 | Identifier float is reserved by PHP core.
 7.0 | method_name      |                    tests/7.0.php:3 | Method name test:test (@php4_constructors) is deprecated.
 7.1 | function         |                    tests/7.1.php:2 | Function mcrypt_decrypt() is deprecated.
 7.1 | ini              |                    tests/7.1.php:4 | Ini session.hash_function is deprecated.
 7.1 | function_usage   |                    tests/7.1.php:7 | Function usage mb_ereg_replace (@mb_ereg_replace_e_modifier) is deprecated.
 7.1 | identifier       |                    tests/7.1.php:9 | Identifier iterable is reserved by PHP core.
 7.2 | function         |                    tests/7.2.php:2 | Function create_function() is deprecated.
 7.2 | function         |                    tests/7.2.php:7 | Function read_exif_data() is deprecated.
 7.2 | constant         |                    tests/7.2.php:9 | Constant INTL_IDNA_VARIANT_2003 is deprecated.
 7.2 | ini              |                    tests/7.2.php:3 | Ini mbstring.func_overload is deprecated.
 7.2 | function_usage   |                    tests/7.2.php:5 | Function usage assert (@assert_on_string) is deprecated.
 7.2 | function_usage   |                   tests/7.2.php:12 | Function usage parse_str (@parse_str_without_argument) is deprecated.

Replace Suggestions:
1. Don't use function mcrypt_generic_end. Instead use mcrypt_generic_deinit
2. Don't use function read_exif_data. Instead use exif_read_data
3. Don't use ini mbstring.http_output. Instead use default_charset
4. Don't use variable $HTTP_RAW_POST_DATA. Instead use php://input
5. Don't use constant INTL_IDNA_VARIANT_2003. Instead use INTL_IDNA_VARIANT_UTS46
Peak memory usage: 1.062 MB

Installation

Phar

The recommended way to install _phpcf_ is as phar-package.

  1. Just download a phar from releases page
  2. Make it executable and put it in one of folders listed in your $PATH: `sh chmod +x phpcf.phar sudo mv phpcf.phar /usr/local/bin/phpcf `

Further I will use commands for PhpCodeFixer installed as phar or globally with composer, but if you've installed it locally with composer, just replace phpcf command with vendor/bin/phpcf.

Composer

Another way to install _phpcf_ is via composer.

  1. If you do not have composer installed, download the composer.phar executable or use the installer.

    `sh $ curl -sS https://getcomposer.org/installer | php `

  2. Run php composer.phar require wapmorgan/php-code-fixer or add requirement in composer.json.

    `json { "require": { "wapmorgan/php-code-fixer": "*" } } `

  3. Run php composer.phar update

Global installation

You can get more profit when _phpcf_ installed globally.

  1. If you do not have composer installed, look previous section and install composer on your server.
  2. Run php composer.phar global require wapmorgan/php-code-fixer

If phpcf installed globally, you can use phpcf command inside any directory.

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagedata (13 files)
Files folder imagesrc (4 files)
Files folder imagetests (9 files)
Plain text file composer.json Data Auxiliary data
Plain text file LICENSE Lic. License text
Plain text file package.json Data Auxiliary data
Plain text file README.md Doc. Documentation
Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Plain text file phpcf Example Example script

  Files folder image Files  /  data  
File Role Description
  Plain text file 5.3.php Aux. Auxiliary script
  Plain text file 5.4.php Aux. Auxiliary script
  Plain text file 5.5.php Aux. Auxiliary script
  Plain text file 5.6.php Aux. Auxiliary script
  Plain text file 7.0.php Aux. Auxiliary script
  Plain text file 7.1.php Aux. Auxiliary script
  Plain text file 7.2.php Aux. Auxiliary script
  Plain text file assert_on_string.php Aux. Auxiliary script
  Plain text file mb_ereg_replace_e_modifier.php Aux. Auxiliary script
  Plain text file parse_str_without_argument.php Aux. Auxiliary script
  Plain text file password_hash_salt_option.php Aux. Auxiliary script
  Plain text file php4_constructors.php Aux. Auxiliary script
  Plain text file preg_replace_e_modifier.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
  Plain text file IssuesBank.php Class Class source
  Plain text file PhpCodeFixer.php Class Class source
  Plain text file Report.php Class Class source
  Plain text file TerminalInfo.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file 5.3.php Aux. Auxiliary script
  Plain text file 5.4.php Aux. Auxiliary script
  Plain text file 5.5.php Aux. Auxiliary script
  Plain text file 5.6.php Aux. Auxiliary script
  Plain text file 7.0.php Class Class source
  Plain text file 7.1.php Class Class source
  Plain text file 7.2.php Aux. Auxiliary script
  Plain text file split.php Class Class source
  Plain text file trait.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:341
This week:1
All time:6,782
This week:624Up
User Ratings User Comments (2)
 All time
Utility:81%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:81%StarStarStarStarStar
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:847