Skip to content

Array Declaration must be short array syntax #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mbniebergall opened this issue Sep 13, 2022 · 5 comments
Closed

Array Declaration must be short array syntax #46

mbniebergall opened this issue Sep 13, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@mbniebergall
Copy link

Currently all of the PSR/PER code examples show using PHP short array syntax $thing = [];. PRs (ex: #18) also use short array syntax $arr = ['a' => 'A', 'b' => 'B', 'c' => 'C'];. There is no rule though requiring short array syntax.

The short array syntax was adopted for good reasons. According to the RFC:

  • Good for framework development when dealing with long parameterlists
  • Other web languages have similar syntax
  • Readable

Scouring Github repositories, PHP short array syntax is very prevalent in popular PHP frameworks. Using the old syntax $thing = array(...); is relatively rare. Most occurrences are in old repositories or in conversion from old to short syntax tools.

Would creating a PR for adding a MUST use short array syntax section be welcomed?

@samdark
Copy link
Member

samdark commented Sep 13, 2022

I think that makes sense.

@samdark samdark added the enhancement New feature or request label Sep 13, 2022
@mbniebergall
Copy link
Author

PR opened for this #47

@mbniebergall
Copy link
Author

After mulling over it and talking with others about arrays and their ambiguity within the coding styles, I created an alternative pull request #48 that is an either-or with #47.

PR 47 is smaller scoped and leaves some aspects not clarified. PR 48 clarifies the uses and declarations for arrays.

@vjik
Copy link
Contributor

vjik commented Sep 17, 2022

#48 is better. For arrays need several rules and use separate section it's OK for me.

@KorvinSzanto
Copy link
Contributor

#48 has merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants