Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

PER 3.1 "opening bracket of a multiline array" ambiguity

Aperta
#159 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
php
Ambito
documentation

Direzione di ricerca

Start with section 11 of the PER 3.1 migration document and specification, then compare its nested-array examples with section 4.7's argument-list rules. The work is done when the wording consistently defines how multiline arrays interact with single- and multi-line calls and the examples no longer conflict.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The PER 3.1 migration document states in section 11:

The opening bracket of a multiline array MUST NOT be placed on its own line. This rule applies to arrays in all contexts, not only assignments. For example:

<?php

return [
    'foo',
    'bar',
];

someFunction([
    'foo',
    'bar',
]);

And the section 11 of the spec states

When an array declaration is split across multiple lines, the opening bracket MUST NOT be placed on its own line.

But the example shown violates this already with the 2nd nested array as in

$arr2 = [
    'multi',
    'line',
    'declaration',
    ['values' => 1, 5, 7],
    [
        'nested',
        'array',
    ],
];

This gets even worse when combined with call argument rules in section 4.7:

Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. A single argument being split across multiple lines (as might be the case with a closure or array) does not constitute splitting the argument list itself.

A multi-argument call written in multi-line style always violates either rules of section 4.7 or 11:

someFunction(
    $baz, [
        'foo',
        'bar',
    ],
);

I think what the addendum in PER 3.1 wants to say is that an array written in multi-line style needs to be treated as a compact single-line item when applying other rules. "Compact single-line item" is no term specified yet and there might be better ones to describe this, but basically similar to a scalar or a variable etc.

This automatically fixes the nested array example in section 11 and its in line with the example shown in the PER 3.1 diff section 11

someFunction([
    'foo',
    'bar',
]);

if this is interpreted as a function call in single-line style.

This is also in line with the example showing a multi-argument call in single-line style in section 4.7:

somefunction($foo, $bar, [
    // ...
], $baz);

As a consequence, it would clarify the ambiguity in multi-argument calls in multi-line style to be

someFunction(
    $baz, 
    [
        'foo',
        'bar',
    ],
);

but also (!):

someFunction(
    [
        'foo',
        'bar',
    ],
    $baz, 
);

It would also mean that a single-argument call written in multi-line style such as

someFunction(
    $someVar,
);

(which is valid according to PER) still enables to write

someFunction(
    [
        'foo',
        'bar',
    ],
);

unless there is a rule enforcing to write single-array-argument calls in single-line style always...

Lingua principale
Nessun dato sulla lingua
Stelle
284
Fork
28
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di php-fig/per-coding-style

Tutte le issue di php-fig/per-coding-style

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.