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 [25.05.2015 20:48] – [Schlüsselwörter und True/False/Null] translated and renamed 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 72: Line 70:
   * PHP [[http://php.net/manual/en/reserved.keywords.php|keywords]] MUST be in lower case.   * PHP [[http://php.net/manual/en/reserved.keywords.php|keywords]] MUST be in lower case.
   * The PHP constants **true**, **false**, and **null** MUST be in lower case.   * The PHP constants **true**, **false**, and **null** MUST be in lower case.
-===== Namensräume und USE-Deklarationen ===== +===== Namespace and Use Declarations ===== 
-  * Wenn vorhandendann MUSS eine Leerzeile nach der Namespace Deklaration sein+  * When presentthere MUST be one blank line after the namespace declaration
-  * Wenn vorhandendann MÜSSEN alle **use** Deklarationen nach der Namespace Deklaration eingefügt werden+  * When presentall **use** declarations MUST go after the namespace declaration
-  * Es DARF NICHT mehr als ein **use** Schlüsselwort pro Deklaration benutzt werden+  * There MUST be one **use** keyword per declaration
-  * Es MUSS eine Leerzeile nach dem **use** Deklarationsblock eingefügt werden+  * There MUST be one blank line after the **use** block
-Beispiel+ 
 +For example:
 <PHP> <PHP>
 <?php <?php
Line 89: Line 88:
 </PHP> </PHP>
  
-===== KlassenEigenschaften und Methoden ===== +===== ClassesProperties, and Methods ===== 
-Das Term 'Klassebetrifft alle KlassenInterfaces und Traits+The term 'classrefers to all classesinterfaces, and traits. 
 +==== Extends and Implements ==== 
 +The **extends** and **implements** keywords MUST be declared on the same line as the class name.
  
-==== Extends und Implements ==== +The opening brace for the class MUST go on its own line; the closing brace for the class MUST go on the next line after the body.
-Die Schlüsselwörter **extends** und **implements** MÜSSEN in der selben Zeile stehen wie der Klassenname. +
- +
-Die öffnende, geschweifte Klammer für die Klasse MUSS alleine in der nächsten freien Zeile stehen. Die zugehörende schließende Klammer exakt darunter in der ersten freien Zeile nach dem Klassenkörper.+
 <PHP> <PHP>
 <?php <?php
Line 109: Line 107:
 } }
 </PHP> </PHP>
-Eine Liste von **implements** KANN über mehrere Zeilen gesplittet werdenwobei jede Unterzeile jeweils einen Schritt eingerückt wird.\\ +Lists of **implements** MAY be split across multiple lineswhere each subsequent line is indented once.\\ 
-Wird das gemachtdann MUSS der erste Eintrag in der nächsten Zeile sein und es DARF NICHT mehr als ein Interface pro Zeile angegeben werden.+When doing sothe first item in the list MUST be on the next line, and there MUST be only one interface per line.
 <PHP> <PHP>
 <?php <?php
Line 128: Line 126:
 </PHP> </PHP>
  
-==== Eigenschaften ==== +==== Properties ==== 
-  * Die Sichtbarkeit MUSS für alle Eigenschaften angegeben werden+  * Visibility MUST be declared on all properties
-  * Das Schlüsselwort **var** DARF NICHT zur Deklaration von Eigenschaften benutzt werden+  * The **var** keyword MUST NOT be used to declare a property
-  * Es DARF NICHT mehr als eine Eigenschaft je Statement deklariert werden+  * There MUST NOT be more than one property declared per statement
-  * Eigenschaftennamen DÜRFEN NICHT zur Kennzeichnung von private oder protected einen _ als Vorzeichen erhalten+  * Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility
-Beispiel einer Eigenschaftendeklaration:+A property declaration looks like the following.
 <PHP> <PHP>
 <?php <?php
Line 144: Line 142:
 </PHP> </PHP>
  
 +==== Methods ====
 +  * Visibility MUST be declared on all methods.
 +  * Method names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility.
 +  * Method names MUST NOT be declared with a space after the method name. The opening brace MUST go on its own line, and the closing brace MUST go on the next line following the body. There MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis.
  
- +A method declaration looks like the followingNote the placement of parenthesescommasspacesand braces:
- +
-==== Methoden ==== +
-  * Die Sichtbarkeit MUSS für alle Methoden angegeben werden. +
-  * Methodennamen DÜRFEN NICHT zur Kennzeichnung von private oder protected einen **_** als Vorzeichen erhalten. +
-  * Nach dem Methodennamen DÜRFEN NICHT Leerstellen eingefügt werden. Die öffnendegeschweifte Klammer MUSS alleine in einer eigenen Zeile stehen und die schließende Klammer MUSS in der nächsten Leeren Zeile nach dem Methodenkörper stehen. Nach der öffnenden und vor der schließenden Klammer der Argumentenliste DÜRFEN NICHT Leerstellen eingefügt werden. +
- +
-Beispiel einer Methodendeklaration. Beachten Sie die Anordnung von KlammernLeerstellenKommata etc.+
 <PHP> <PHP>
 <?php <?php
Line 166: Line 161:
 </PHP> </PHP>
  
- +==== Method Arguments ==== 
- +  * In the argument list, there MUST NOT be a space before each commaand there MUST be one space after each comma
- +  * Method arguments with default values MUST go at the end of the argument list.
- +
-==== Methoden Argumente ==== +
-  * In der Argumentenliste DARF NICHT eine Leerstelle vor einem Komma seinaber es MUSS eine Leerstelle nach jedem Komma folgen+
-  * Methodenargumente mit Vorgabewerten(default) MÜSSEN an das Ende der Liste.+
 <PHP> <PHP>
 <?php <?php
Line 185: Line 176:
 } }
 </PHP> </PHP>
-  * Argumentenlisten 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 je Zeile angegeben werden+  * Argument 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 per line
-  * Wenn eine Argumentenliste gesplittet wirdso 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 linesthe closing parenthesis and opening brace MUST be placed together on their own line with one space between them.
 <PHP> <PHP>
 <?php <?php
Line 203: Line 194:
 </PHP> </PHP>
  
- +==== abstract, final, and static ==== 
- +  * When presentthe **abstract** and **final** declarations MUST precede the visibility declaration
- +  * When presentthe **static** declaration MUST come after the visibility declaration.
-==== abstract, final und static ==== +
-  * Wenn vorhandenMÜSSEN die Deklarationen für **abstract** und **final** vor der Sichtbarkeitsdeklaration eingefügt werden+
-  * Wenn vorhandenMUSS die Deklarationen für **static** nach der Sichtbarkeitsdeklaration eingefügt werden.+
 <PHP> <PHP>
 <?php <?php
Line 226: Line 214:
 </PHP> </PHP>
  
- +==== 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, there MUST NOT be a space __after__ the opening parenthesis, and there MUST NOT be a space __before__ the closing parenthesis. In the argument list, there MUST NOT be a space __before__ each comma, and there MUST be one space __after__ each comma.
- +
- +
-==== 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 238: Line 222:
 </PHP> </PHP>
  
-  * Argumentenlisten 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 je Zeile angegeben werden+  * Argument 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 per line
-  * Wenn eine Argumentenliste gesplittet wirdso MUSS die schließende Klammer und das Semikolon ohne eine Leerstelle dazwischen in eine eigene Zeile.+  * When splitting an argument listthe closing parenthesis MUST be on a separate line without a space character in between.
 <PHP> <PHP>
 $foo->bar( $foo->bar(
Line 248: 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 271: 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 295: 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 305: 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 311: 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 321: 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 332: 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 341: Line 314:
 } catch (OtherExceptionType $e) { } catch (OtherExceptionType $e) {
     // catch body     // catch body
 +} finally {
 +    // finally body
 } }
 </PHP> </PHP>
Line 346: 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 361: 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 409: 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 419: Line 394:
 ); );
 </PHP> </PHP>
- 
- 
- 
- 
  
  
en/dev/all/psr/psr-2.1432586891.txt.gz · Last modified: 03.06.2015 15:55 (external edit)