@@ -279,6 +279,7 @@ Declare statements MUST NOT contain any spaces and MUST be exactly `declare(stri
279279
280280Block declare statements are allowed and MUST be formatted as below. Note position of
281281braces and spacing:
282+
282283``` php
283284declare(ticks=1) {
284285 // some code
@@ -293,7 +294,7 @@ Any closing brace MUST NOT be followed by any comment or statement on the
293294same line.
294295
295296When instantiating a new class, parentheses MUST always be present even when
296- there are no arguments passed to the constructor.
297+ there are no arguments passed to the constructor. For example:
297298
298299``` php
299300new Foo();
@@ -312,15 +313,13 @@ class MyException extends \RuntimeException {}
312313The ` extends ` and ` implements ` keywords MUST be declared on the same line as
313314the class name.
314315
315- The opening brace for the class MUST go on its own line; the closing brace
316- for the class MUST go on the next line after the body.
317-
318- Opening braces MUST be on their own line and MUST NOT be preceded or followed
319- by a blank line.
316+ The opening brace for the class MUST go on its own line, and MUST NOT be
317+ preceded or followed by a blank line.
320318
321- Closing braces MUST be on their own line and MUST NOT be preceded by a blank
322- line.
319+ The closing brace for the class MUST go on its own line, immediately following
320+ the last line of the class body, and MUST NOT be preceded by a blank line.
323321
322+ The following is a validly formatted class:
324323
325324``` php
326325<?php
@@ -340,7 +339,7 @@ class ClassName extends ParentClass implements \ArrayAccess, \Countable
340339Lists of ` implements ` and, in the case of interfaces, ` extends ` MAY be split
341340across multiple lines, where each subsequent line is indented once. When doing
342341so, the first item in the list MUST be on the next line, and there MUST be only
343- one interface per line.
342+ one interface per line. For example:
344343
345344``` php
346345<?php
@@ -365,22 +364,11 @@ class ClassName extends ParentClass implements
365364The ` use ` keyword used inside the classes to implement traits MUST be
366365declared on the next line after the opening brace.
367366
368- ``` php
369- <?php
370-
371- namespace Vendor\Package;
372-
373- use Vendor\Package\FirstTrait;
374-
375- class ClassName
376- {
377- use FirstTrait;
378- }
379- ```
380-
381367Each individual trait that is imported into a class MUST be included
382368one-per-line and each inclusion MUST have its own ` use ` import statement.
383369
370+ The following is a correct example of trait ` use ` age.
371+
384372``` php
385373<?php
386374
@@ -400,6 +388,7 @@ class ClassName
400388
401389When the class has nothing after the ` use ` import statement, the class
402390closing brace MUST be on the next line after the ` use ` import statement.
391+ For example:
403392
404393``` php
405394<?php
@@ -414,7 +403,7 @@ class ClassName
414403}
415404```
416405
417- Otherwise, it MUST have a blank line after the ` use ` import statement.
406+ Otherwise, it MUST have a blank line after the ` use ` import statement, as in:
418407
419408``` php
420409<?php
@@ -431,7 +420,7 @@ class ClassName
431420}
432421```
433422
434- When using the ` insteadof ` and ` as ` operators they must be used as follows taking
423+ When using the ` insteadof ` and ` as ` operators they MUST be used as follows taking
435424note of indentation, spacing, and new lines.
436425
437426``` php
@@ -552,7 +541,7 @@ In the argument list, there MUST NOT be a space before each comma, and there
552541MUST be one space after each comma.
553542
554543Method and function parameters with default values MUST go at the end of the argument
555- list.
544+ list. For example:
556545
557546``` php
558547<?php
@@ -574,7 +563,7 @@ next line, and there MUST be only one argument per line.
574563
575564When the argument list is split across multiple lines, the closing parenthesis
576565and opening brace MUST be placed together on their own line with one space
577- between them.
566+ between them. For example:
578567
579568``` php
580569<?php
@@ -596,7 +585,7 @@ class ClassName
596585When you have a return type declaration present, there MUST be one space after
597586the colon followed by the type declaration. The colon and declaration MUST be
598587on the same line as the argument list closing parenthesis with no spaces between
599- the two characters.
588+ the two characters. For example:
600589
601590``` php
602591<?php
@@ -623,7 +612,7 @@ class ReturnTypeVariations
623612```
624613
625614In nullable type declarations, there MUST NOT be a space between the question mark
626- and the type.
615+ and the type. For example:
627616
628617``` php
629618<?php
@@ -678,6 +667,8 @@ engine and language handles them. When present, they MUST be in the following o
678667
679668All keywords MUST be on a single line, and MUST be separated by a single space.
680669
670+ The following is a correct example of modifier keyword usage:
671+
681672``` php
682673<?php
683674
@@ -711,6 +702,8 @@ after the opening parenthesis, and there MUST NOT be a space before the
711702closing parenthesis. In the argument list, there MUST NOT be a space before
712703each comma, and there MUST be one space after each comma.
713704
705+ The following lines show correct calls:
706+
714707``` php
715708<?php
716709
@@ -725,6 +718,8 @@ next line, and there MUST be only one argument per line. A single argument being
725718split across multiple lines (as might be the case with an anonymous function or
726719array) does not constitute splitting the argument list itself.
727720
721+ The following examples show correct argument usage.
722+
728723``` php
729724<?php
730725
@@ -748,14 +743,14 @@ $app->get('/hello/{name}', function ($name) use ($app) {
748743```
749744
750745If using named arguments, there MUST NOT be a space between the argument name
751- and colon, and there MUST be a single space between the colon and the argument value.
746+ and colon, and there MUST be a single space between the colon and the argument value. For example:
752747
753748``` php
754749somefunction($a, b: $b, c: 'c');
755750```
756751
757752Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first
758- method MUST be on the next line.
753+ method MUST be on the next line. For example:
759754
760755``` php
761756$someInstance
@@ -815,6 +810,8 @@ placed together on their own line with one space between them. Boolean
815810operators between conditions MUST always be at the beginning or at the end of
816811the line, not a mix of both.
817812
813+ For example:
814+
818815``` php
819816<?php
820817
@@ -867,6 +864,8 @@ placed together on their own line with one space between them. Boolean
867864operators between conditions MUST always be at the beginning or at the end of
868865the line, not a mix of both.
869866
867+ For example:
868+
870869``` php
871870<?php
872871
936935Expressions in parentheses MAY be split across multiple lines, where each
937936subsequent line is indented at least once. When doing so, the first condition
938937MUST be on the next line. Boolean operators between conditions MUST
939- always be at the beginning or at the end of the line, not a mix of both.
938+ always be at the beginning or at the end of the line, not a mix of both. For example:
940939
941940``` php
942941<?php
@@ -965,7 +964,8 @@ for ($i = 0; $i < 10; $i++) {
965964Expressions in parentheses MAY be split across multiple lines, where each
966965subsequent line is indented at least once. When doing so, the first expression
967966MUST be on the next line. The closing parenthesis and opening brace MUST be
968- placed together on their own line with one space between them.
967+ placed together on their own line with one space between them. The semicolons
968+ MUST be on the component the follow, not on the subsequent line. For example:
969969
970970``` php
971971<?php
@@ -1023,7 +1023,7 @@ All operators not described here are left undefined.
10231023### 6.1. Unary operators
10241024
10251025The increment/decrement operators MUST NOT have any space between
1026- the operator and operand.
1026+ the operator and operand:
10271027
10281028``` php
10291029$i++;
@@ -1063,6 +1063,7 @@ $variable = $foo ? 'foo' : 'bar';
10631063
10641064When the middle operand of the conditional operator is omitted, the operator
10651065MUST follow the same style rules as other binary [ comparison] [ ] operators:
1066+
10661067``` php
10671068$variable = $foo ?: 'bar';
10681069```
@@ -1231,7 +1232,7 @@ the list of `implements` interfaces does not wrap. If the list of interfaces
12311232wraps, the brace MUST be placed on the line immediately following the last
12321233interface.
12331234
1234- If the anonymous class has no arguments, the ` () ` after ` class ` MUST be omitted.
1235+ If the anonymous class has no arguments, the ` () ` after ` class ` MUST be omitted. For example:
12351236
12361237``` php
12371238<?php
@@ -1271,6 +1272,8 @@ Enum case declarations MUST use PascalCase capitalization. Enum case declaratio
12711272Constants in Enumerations MAY use either PascalCase or UPPER_CASE capitalization. PascalCase is RECOMMENDED,
12721273so that it is consistent with case declarations.
12731274
1275+ The following example shows a typical valid Enum:
1276+
12741277``` php
12751278enum Suit: string
12761279{
@@ -1296,6 +1299,7 @@ indentation they are declared in.
12961299
12971300The following is *** not allowed*** due to the heredoc beginning on a
12981301different line than the context it's being declared in:
1302+
12991303``` php
13001304$notAllowed =
13011305<<<'COUNTEREXAMPLE'
@@ -1306,11 +1310,12 @@ $notAllowed =
13061310 COUNTEREXAMPLE;
13071311```
13081312
1309- Instead the heredoc MUST be declared on the same line as the variable
1313+ Instead, the heredoc MUST be declared on the same line as the variable
13101314declaration it's being set against.
13111315
13121316The follow is *** not allowed*** due to the scope indention not matching the scope the
13131317heredoc is declared in:
1318+
13141319``` php
13151320function notAllowed()
13161321{
@@ -1328,6 +1333,7 @@ it's declared in.
13281333
13291334The following is an example of both a heredoc and a nowdoc declared in a
13301335compliant way:
1336+
13311337``` php
13321338function allowed()
13331339{
@@ -1383,6 +1389,8 @@ MUST be placed on the next line after the last value. There MUST NOT be more
13831389than one value assignment per line. Value assignments MAY use a single line
13841390or multiple lines.
13851391
1392+ The following example shows correct array usage:
1393+
13861394```php
13871395<?php
13881396
0 commit comments