This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:dev:all:psr:psr-2 [26.05.2015 19:53] – [Kontrollstrukturen] renamed and translated mrbaseman | en:dev:all:psr:psr-2 [31.03.2017 06:59] (current) – [try, catch] Manuela v.d.Decken | ||
---|---|---|---|
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 244: | Line 242: | ||
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. | 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 254: | 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 278: | 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 288: | 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 294: | 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 304: | 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 315: | Line 305: | ||
- | ==== try, catch ==== | + | ==== try, catch, finally |
- | 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 324: | Line 314: | ||
} catch (OtherExceptionType $e) { | } catch (OtherExceptionType $e) { | ||
// catch body | // catch body | ||
+ | } finally { | ||
+ | // finally body | ||
} | } | ||
</ | </ | ||
Line 329: | Line 321: | ||
===== 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 344: | Line 336: | ||
}; | }; | ||
</ | </ | ||
- | * 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 392: | Line 384: | ||
}; | }; | ||
</ | </ | ||
- | 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 402: | Line 394: | ||
); | ); | ||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||