User Tools

Site Tools


en:dev:all:psr:psr-2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:dev:all:psr:psr-2 [26.05.2015 19:49] – [Methoden- und Funktionsaufrufe] renamed and translated mrbasemanen: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://www.php-fig.org/psr/psr-2/|PHP-FIG PSR-2]][/size] [size=10]originating from  [[http://www.php-fig.org/psr/psr-2/|PHP-FIG PSR-2]][/size]
 ====== Coding Style Guide ====== ====== Coding Style Guide ======
Line 234: Line 232:
 </PHP> </PHP>
  
-===== 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, geschweifte Klammer MUSS in der Zeile nach dem Kontrollkörper stehen. +  * The closing brace MUST be on the next line after the body 
-Der Körper einer Struktur MUSS in geschweifte Klammern eingeschlossen werdenDiese Standardisierung verhindert Fehlerfalls zufällig Leerzeilen im Körper eingefügt werden. +The body of each structure MUST be enclosed by bracesThis standardizes how the structures lookand 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 ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern. Die Schlüsselwörter **else** und **elseif** MÜSSEN sich mit einer Leerstelle Abstand auf der selben Zeile befinden, wie die schließende, geschweifte Klammer des vorhergehenden Strukturkörpers.+An **if** structure looks like the followingNote the placement of parenthesesspaces, and braces; and that **else** and **elseif** MUST be on the same line as the closing brace from the earlier body separated by one space character.
 <PHP> <PHP>
 if ($expr1) { if ($expr1) {
Line 257: Line 252:
 } }
 </PHP> </PHP>
-Das Schlüsselwort **elseif** SOLLTE anstelle von **else if** so dass alle Schlüsselworte wie einzelne Worte aussehen. +The keyword **elseif** SHOULD be used instead of **else if** so that all control keywords look like single words.
- +
 ==== switch, case ==== ==== switch, case ====
-Eine **switch**-Struktur sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern. +**switch** structure looks like the followingNote the placement of parentheses, spacesand bracesThe **case** statement MUST be indented once from **switch**, and the **break** keyword (or other terminating keywordMUST be indented at the same level as the **case** bodyThere MUST be a comment such as %%//%%// no break// when 'fall-throughis intentional in a non-empty **case** body.
-Das **case**-Statement MUSS eine Stufe ab **switch** eingerückt werden und das **break** Schlüsselwort (oder ein anderes, abschließendes SchlüsselwortMUSS auf die selbe Ebene eingerückt werden, wie der **case**-KörperEs MUSS ein Kommentar wie %%//%%// no break//  eingefügt werden, wenn ein 'durchfallenzum nächsten **case** erwünscht ist.+
 <PHP> <PHP>
 switch ($expr) { switch ($expr) {
Line 281: Line 273:
 } }
 </PHP> </PHP>
- 
- 
  
 ==== while, do while ==== ==== while, do while ====
-Ein **while**-Statement sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern.+**while** statement looks like the followingNote the placement of parenthesesspaces, and braces.
 <PHP> <PHP>
 while ($expr) { while ($expr) {
Line 291: Line 281:
 } }
 </PHP> </PHP>
-ebenso sieht ein **do while**-Statement wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern.+Similarly, a **do while** statement looks like the followingNote the placement of parentheses, spacesand braces.
 <PHP> <PHP>
 do { do {
Line 297: Line 287:
 } while ($expr); } while ($expr);
 </PHP> </PHP>
- 
- 
  
 ==== for ==== ==== for ====
-Ein **for**-Statement sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern+**for** statement looks like the followingNote the placement of parenthesesspaces, and braces.
 <PHP> <PHP>
 for ($i = 0; $i < 10; $i++) { for ($i = 0; $i < 10; $i++) {
Line 307: Line 295:
 } }
 </PHP> </PHP>
- 
  
 ==== foreach ==== ==== foreach ====
-Ein **foreach**-Statement sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern+**foreach** statement looks like the followingNote the placement of parenthesesspaces, and braces.
 <PHP> <PHP>
 foreach ($iterable as $key => $value) { foreach ($iterable as $key => $value) {
Line 318: Line 305:
  
  
-==== try, catch ==== +==== try, catch, finally ==== 
-Ein **try catch**-Statement sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern+**try catch** block looks like the followingNote the placement of parentheses, spacesand braces.
 <PHP> <PHP>
 try { try {
Line 327: Line 314:
 } catch (OtherExceptionType $e) { } catch (OtherExceptionType $e) {
     // catch body     // catch body
 +} finally {
 +    // finally body
 } }
 </PHP> </PHP>
Line 332: Line 321:
  
 ===== Closures ===== ===== Closures =====
-  * Closures MÜSSEN mit einem Leerzeichen nach denm Schlüsselwort **function** und je einem Leerzeichen vor und nach dem Schlüsselwort **use** deklariert werden+  * Closures MUST be declared with a space after the **function** keyword, and a space before and after the **use** keyword
-  * Die öffnende, geschweifte Klammer MUSS in der selben Zeile wie das Schlüsselwort **function** sein und die schließende Klammer MUSS in der nächsten Zeile nach dem Funktionskörper sein+  * The opening brace MUST go on the same line as the **function** keyword, and the closing brace MUST go on the next line following the body
-  * 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 Argumente mit Vorgabewerten (default) MÜSSEN an das Ende der Argumentenliste+  * Closure arguments with default values MUST go at the end of the argument list
-Eine Closure Deklaration sieht wie nachfolgend ausBeachten Sie die Plazierung von KlammernLeerstellen und geschweiften Klammern. +A closure declaration looks like the followingNote the placement of parenthesescommas, spaces, and braces:
 <PHP> <PHP>
 $closureWithArgs = function ($arg1, $arg2) { $closureWithArgs = function ($arg1, $arg2) {
Line 347: Line 336:
 }; };
 </PHP> </PHP>
-  * Argumenten- und Variablenlisten KÖNNEN über mehrere Zeilen gesplittet werdenwenn jede Unterzeile um eine Stufe eingerückt wirdWenn so verfahren wirdMUSS das erste Element in die nächste Zeile und es DARF NICHT mehr als ein Argument oder Variable je Zeile angegeben werden+  * Argument lists and variable lists MAY be split across multiple lineswhere each subsequent line is indented onceWhen 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 wirdso 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 linesthe 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 395: Line 384:
 }; };
 </PHP> </PHP>
-Beachten Sie, dass die Formatierungsregeln auch greifen, wenn ein  Closure direkt in einem Funktions- oder Methodenaufruf als Argument eingesetzt ist.+Note that the formatting rules also apply when the closure is used directly in a function or method call as an argument.
 <PHP> <PHP>
 $foo->bar( $foo->bar(
Line 405: Line 394:
 ); );
 </PHP> </PHP>
- 
- 
- 
- 
  
  
en/dev/all/psr/psr-2.1432669741.txt.gz · Last modified: 03.06.2015 15:55 (external edit)