Skip to content

Convert all "long" array syntax to "short" syntax, and make it the official standard? #7191

Description

@swampopus

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/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions