Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

php-short-array-syntax-converter

> 编程语言
Open source

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

371 stars0 likes1 views
WebsiteGitHub

About

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

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 (` -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 (German CV editor) for sponsoring the development.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言