Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomasbachem/php-short-array-syntax-converter
Command-line script to convert PHP's array() syntax to PHP 5.4's short array syntax []
https://github.com/thomasbachem/php-short-array-syntax-converter
Last synced: 15 days ago
JSON representation
Command-line script to convert PHP's array() syntax to PHP 5.4's short array syntax []
- Host: GitHub
- URL: https://github.com/thomasbachem/php-short-array-syntax-converter
- Owner: thomasbachem
- Created: 2012-04-25T02:55:51.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-05-10T08:45:41.000Z (over 5 years ago)
- Last Synced: 2024-08-02T00:25:58.796Z (4 months ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 373
- Watchers: 9
- Forks: 35
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP 5.4 Short Array Syntax Converter
================================Command-line script to convert and revert 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.
Usage
================================Usage: php convert.php [-w]
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.If you want the script to process PHP files with short open tags (``) as well, you need to make sure that the [`short_open_tag`](http://php.net/manual/ini.core.php#ini.short-open-tag) setting is enabled in your `php.ini` file.
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 (on Linux/Mac):
find -name "*.php" -exec php "convert.php" -w "{}" \;
Or on Windows (thanks to John Jablonski for suggesting):
FOR /f "tokens=*" %a in ('dir *.php /S/B') DO php convert.php %a -w
In case you don't trust the script yet, you can even perform a syntax check after conversion:find -name "*.php" -exec php -l "{}" \; | grep "error:"
Revert
================================Usage: php revert.php [-w]
**Reverting has not yet been thoroughly tested, so use with extreme percaution!**
Since there is no specific token for the short array syntax, it assumes every "[" is an aray and relies on checking the previous token for a variable, object property, function return ")", nested array "]" and variable reference "}".
Thanks to
================================
Thanks to [Lebenslauf.com](https://lebenslauf.com) (German CV editor) for sponsoring the development.