This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:dev:all:psr:psr-2 [26.05.2015 19:33] – [Methoden] renamed and translated mrbaseman | en:dev:all:psr:psr-2 [26.05.2015 20:23] – finished translation mrbaseman | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// | ||
- | |||
[size=10]originating from [[http:// | [size=10]originating from [[http:// | ||
====== Coding Style Guide ====== | ====== Coding Style Guide ====== | ||
Line 163: | Line 161: | ||
</ | </ | ||
- | ==== Methoden Argumente | + | ==== Method Arguments |
- | * In der Argumentenliste DARF NICHT eine Leerstelle vor einem Komma sein, aber es MUSS eine Leerstelle nach jedem Komma folgen. | + | * In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. |
- | * Methodenargumente mit Vorgabewerten(default) MÜSSEN an das Ende der Liste. | + | * Method arguments with default |
<PHP> | <PHP> | ||
<?php | <?php | ||
Line 178: | Line 176: | ||
} | } | ||
</ | </ | ||
- | * Argumentenlisten KÖNNEN über mehrere Zeilen gesplittet werden, wenn jede Unterzeile um eine Stufe eingerückt wird. Wenn so verfahren wird, MUSS das erste Element | + | * 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. |
- | * Wenn eine Argumentenliste gesplittet wird, so MUSS die schließende Klammer und die öffnende geschweifte Klammer mit einer Leerstelle dazwischen in eine eigene Zeile. | + | * When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. |
<PHP> | <PHP> | ||
<?php | <?php | ||
Line 196: | Line 194: | ||
</ | </ | ||
- | + | ==== abstract, final, and static ==== | |
- | + | * When present, the **abstract** | |
- | + | * When present, the **static** | |
- | ==== abstract, final und static ==== | + | |
- | * Wenn vorhanden, MÜSSEN die Deklarationen für **abstract** | + | |
- | * Wenn vorhanden, MUSS die Deklarationen für **static** | + | |
<PHP> | <PHP> | ||
<?php | <?php | ||
Line 219: | Line 214: | ||
</ | </ | ||
- | + | ==== Method and Function Calls ==== | |
- | + | When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis, | |
- | + | ||
- | + | ||
- | ==== Methoden- und Funktionsaufrufe | + | |
- | Bei einem Methoden- oder Funktionsaufruf DARF NICHT zwischen dem Methoden- oder Funktionsnamen und der öffnenden Klammer eine Leerstelle sein; Es DARF NICHT eine Leerstelle __nach__ der öffnenden Klammer und es DARF NICHT eine Leerstelle __vor__ der schließenden Klammer eingefügt werden. In der Argumentenliste DARF NICHT eine Leerstelle __vor__ einem Komma stehen und es MUSS eine Leerstelle __nach__ jedem Komma eingefügt werden. | + | |
<PHP> | <PHP> | ||
bar(); | bar(); | ||
Line 231: | Line 222: | ||
</ | </ | ||
- | * Argumentenlisten KÖNNEN über mehrere Zeilen gesplittet werden, wenn jede Unterzeile um eine Stufe eingerückt wird. Wenn so verfahren wird, MUSS das erste Element | + | * 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. |
- | * Wenn eine Argumentenliste gesplittet wird, so MUSS die schließende Klammer und das Semikolon ohne eine Leerstelle dazwischen | + | * When splitting an argument list, the closing parenthesis MUST be on a separate line without a space character |
<PHP> | <PHP> | ||
$foo-> | $foo-> | ||
Line 241: | Line 232: | ||
</ | </ | ||
- | ===== Kontrollstrukturen | + | ===== Control Structures |
- | Für alle Kontrollstrukturen gelten erst einmal folgende, allgemeine Regeln: | + | The general style rules for control structures are as follows: |
- | * Es MUSS ein Leerzeichen hinter dem Schlüsselwort der Kontrollstruktur sein. | + | * There MUST be one space after the control structure keyword |
- | * Es DARF NICHT ein Leerzeichen nach der öffnenden Klammer stehen. | + | * There MUST NOT be a space after the opening parenthesis |
- | * Es DARF NICHT ein Leerzeichen vor der schließenden Klammer stehen. | + | * There MUST NOT be a space before the closing parenthesis |
- | * Es MUSS ein Leerzeichen zwischen der schließenden Klammer und der öffnenden, geschweiften Klammer stehen. | + | * There MUST be one space between the closing parenthesis and the opening brace |
- | * Der Strukturkörper MUSS um eine Stufe eingerückt werden. | + | * The structure body MUST be indented once |
- | * Die schließende, | + | * The closing brace MUST be on the next line after the body |
- | Der Körper einer Struktur MUSS in geschweifte Klammern eingeschlossen werden. Diese Standardisierung verhindert Fehler, falls zufällig Leerzeilen im Körper eingefügt werden. | + | The body of each structure MUST be enclosed by braces. This standardizes how the structures look, and reduces the likelihood of introducing errors as new lines get added to the body. |
- | + | ||
- | + | ||
==== if, elseif, else ==== | ==== if, elseif, else ==== | ||
- | Eine **if**-Struktur sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. Die Schlüsselwörter | + | An **if** |
<PHP> | <PHP> | ||
if ($expr1) { | if ($expr1) { | ||
Line 264: | Line 252: | ||
} | } | ||
</ | </ | ||
- | Das Schlüsselwort | + | The keyword |
- | + | ||
==== switch, case ==== | ==== switch, case ==== | ||
- | Eine **switch**-Struktur sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A **switch** |
- | Das **case**-Statement MUSS eine Stufe ab **switch** | + | |
<PHP> | <PHP> | ||
switch ($expr) { | switch ($expr) { | ||
Line 288: | Line 273: | ||
} | } | ||
</ | </ | ||
- | |||
- | |||
==== while, do while ==== | ==== while, do while ==== | ||
- | Ein **while**-Statement sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A **while** |
<PHP> | <PHP> | ||
while ($expr) { | while ($expr) { | ||
Line 298: | Line 281: | ||
} | } | ||
</ | </ | ||
- | ebenso sieht ein **do while**-Statement wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | Similarly, a **do while** |
<PHP> | <PHP> | ||
do { | do { | ||
Line 304: | Line 287: | ||
} while ($expr); | } while ($expr); | ||
</ | </ | ||
- | |||
- | |||
==== for ==== | ==== for ==== | ||
- | Ein **for**-Statement sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A **for** |
<PHP> | <PHP> | ||
for ($i = 0; $i < 10; $i++) { | for ($i = 0; $i < 10; $i++) { | ||
Line 314: | Line 295: | ||
} | } | ||
</ | </ | ||
- | |||
==== foreach ==== | ==== foreach ==== | ||
- | Ein **foreach**-Statement sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A **foreach** |
<PHP> | <PHP> | ||
foreach ($iterable as $key => $value) { | foreach ($iterable as $key => $value) { | ||
Line 326: | Line 306: | ||
==== try, catch ==== | ==== try, catch ==== | ||
- | Ein **try catch**-Statement sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A **try catch** |
<PHP> | <PHP> | ||
try { | try { | ||
Line 339: | Line 319: | ||
===== Closures ===== | ===== Closures ===== | ||
- | * Closures | + | * Closures |
- | * Die öffnende, geschweifte Klammer MUSS in der selben Zeile wie das Schlüsselwort | + | * The opening brace MUST go on the same line as the **function** |
- | * Nach der öffnenden Klammer der Argumentenliste DARF NICHT ein Leerzeichen stehen und vor der schließenden Klammer DARF NICHT ein Leerzeichen sein. | + | * There MUST NOT be a space after the opening parenthesis of the argument list or variable list, and there MUST NOT be a space before the closing parenthesis of the argument list or variable list. |
- | * In der Argumentenliste und der Variablenliste DARF NICHT ein Leerzeichen vor einem Komma stehen und nach einem Komma MUSS ein Leerzeichen sein. | + | * In the argument list and variable list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. |
- | * Closure | + | * Closure |
- | Eine Closure Deklaration sieht wie nachfolgend aus. Beachten Sie die Plazierung von Klammern, Leerstellen und geschweiften Klammern. | + | A closure declaration looks like the following. Note the placement of parentheses, commas, spaces, and braces: |
<PHP> | <PHP> | ||
$closureWithArgs = function ($arg1, $arg2) { | $closureWithArgs = function ($arg1, $arg2) { | ||
Line 354: | Line 334: | ||
}; | }; | ||
</ | </ | ||
- | * Argumenten- und Variablenlisten KÖNNEN über mehrere Zeilen gesplittet werden, wenn jede Unterzeile um eine Stufe eingerückt wird. Wenn so verfahren wird, MUSS das erste Element | + | * Argument lists and variable 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 or variable per line. |
- | * Wenn eine Argumenten- oder Variablenliste gesplittet wird, so MUSS die schließende Klammer und die öffnende geschweifte Klammer mit einer Leerstelle dazwischen in eine eigene Zeile. | + | * When the ending list (whether or arguments or variables) is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. |
- | Beispiele von Closures mit und ohne Argumentenliste und Variableliste die über mehrere Zeilen gesplittet sind. | + | * The following are examples of closures with and without argument lists and variable lists split across multiple lines. |
<PHP> | <PHP> | ||
$longArgs_noVars = function ( | $longArgs_noVars = function ( | ||
Line 402: | Line 382: | ||
}; | }; | ||
</ | </ | ||
- | Beachten Sie, dass die Formatierungsregeln auch greifen, wenn ein Closure direkt | + | Note that the formatting rules also apply when the closure is used directly |
<PHP> | <PHP> | ||
$foo-> | $foo-> | ||
Line 412: | Line 392: | ||
); | ); | ||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||