Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Command-line script to convert PHP's array() syntax to PHP 5.4's short array syntax []

Notifications You must be signed in to change notification settings

infomaxwebsolutions/php-short-array-syntax-converter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP 5.4 Short Array Syntax Converter

Command-line script to convert PHP's array() syntax to PHP 5.4's short array syntax [] using PHP's built-in tokenizer.

By relying on the PHP tokenizer, nothing but the array syntax itself will be altered. The script was successfully tested against code bases with more than 5.000 PHP files.

Installation via Composer

Just add "thomasbachem/php-short-array-syntax-converter": "dev-master" to your require(-dev) section and run update command on Composer.

Usage

Usage: php array-converter.php [-w] <file>

Run the script with the path of the PHP file you wish to convert as argument. This will print the converted source code to STDOUT.

You can add the -w switch if you want to override the original file with the converted code.

In case of any error, an error message is written to STDERR and the script exits with a return code of 1.

Use find to convert a whole directory recursively:

find <directory> -name "*.php" -exec php "array-converter.php" -w "{}" \;

In case you don't trust the script yet, you can even perform a syntax check after conversion:

find <directory> -name "*.php" -exec php -l "{}" \; | grep "error:"

Thanks to

Thanks to Lebenslauf.com (German CV editor) for sponsoring the development.

About

Command-line script to convert PHP's array() syntax to PHP 5.4's short array syntax []

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%