PHP 5.4 Short Arrays Converter

Command-line script to convert between array() and PHP 5.4's short syntax []. It uses native PHP tokenizer, so conversion is safe. The script was successfully tested against thousands of PHP files.

Download from GitHub

To convert all *.php and *.phpt files in whole directory recursively or to convert a single file use:

convert.php <directory | file>

To convert source code from STDIN and print the output to STDOUT use:

convert.php < input.php > output.php

To convert short syntax [] to older long syntax array() use option --reverse:

convert.php --reverse [<directory | file>]

10 years ago in section PHP | blog written by David Grudl | back to top

David Grudl Open-source creator and AI specialist who opens doors to the world of artificial intelligence. His projects including Nette and Texy! power websites you visit daily. He contributes to Uměligence and La Trine while hosting Tech Guys. Through AI workshops, he champions technology that genuinely improves people's lives.

You might be interested in


phpFashion © 2004, 2025 David Grudl | o blogu

Ukázky zdrojových kódů smíte používat s uvedením autora a URL tohoto webu bez dalších omezení.