The Question:
In core, should we stop using array(1, 2, 3) in favor of [1, 2, 3] ? And, should we adopt short syntax as the standard way of writing arrays in Backdrop?
Example:
$x = [
'key' => 'val',
];
function ($x = []) {}
return l('foo', 'bar', ['attributes' => ['class' => 'fun']]);
Previous work on short syntax
@quicksketch has already created a working proof of concept for a rapid conversion to short syntax: backdrop/backdrop#4936
In case the blog post he mentioned disappears one day, here is what it said to do:
1. Require code sniffer in your project (you are using composer, right?)
`composer require --dev squizlabs/php_codesniffer`
2. Run CBF using the DisallowLongArraySyntax sniff
`vendor/bin/phpcbf . --standard=Generic --sniffs=Generic.Arrays.DisallowLongArraySyntax`
That will apply to everything in the current directory, so simply change the . to whichever specific files/folders you want to affect.
-- from https://philipjohn.blog/2023/02/10/convert-php-arrays-to-short-array-syntax-in-seconds/
The Question:
In core, should we stop using
array(1, 2, 3)in favor of[1, 2, 3]? And, should we adopt short syntax as the standard way of writing arrays in Backdrop?Example:
Previous work on short syntax
@quicksketch has already created a working proof of concept for a rapid conversion to short syntax: backdrop/backdrop#4936
In case the blog post he mentioned disappears one day, here is what it said to do:
-- from https://philipjohn.blog/2023/02/10/convert-php-arrays-to-short-array-syntax-in-seconds/