@@ -279,6 +279,7 @@ Declare statements MUST NOT contain any spaces and MUST be exactly `declare(stri
279
279
280
280
Block declare statements are allowed and MUST be formatted as below. Note position of
281
281
braces and spacing:
282
+
282
283
``` php
283
284
declare(ticks=1) {
284
285
// some code
@@ -293,7 +294,7 @@ Any closing brace MUST NOT be followed by any comment or statement on the
293
294
same line.
294
295
295
296
When 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:
297
298
298
299
``` php
299
300
new Foo();
@@ -312,15 +313,13 @@ class MyException extends \RuntimeException {}
312
313
The ` extends ` and ` implements ` keywords MUST be declared on the same line as
313
314
the class name.
314
315
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.
320
318
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.
323
321
322
+ The following is a validly formatted class:
324
323
325
324
``` php
326
325
<?php
@@ -340,7 +339,7 @@ class ClassName extends ParentClass implements \ArrayAccess, \Countable
340
339
Lists of ` implements ` and, in the case of interfaces, ` extends ` MAY be split
341
340
across multiple lines, where each subsequent line is indented once. When doing
342
341
so, 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:
344
343
345
344
``` php
346
345
<?php
@@ -365,22 +364,11 @@ class ClassName extends ParentClass implements
365
364
The ` use ` keyword used inside the classes to implement traits MUST be
366
365
declared on the next line after the opening brace.
367
366
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
-
381
367
Each individual trait that is imported into a class MUST be included
382
368
one-per-line and each inclusion MUST have its own ` use ` import statement.
383
369
370
+ The following is a correct example of trait ` use ` age.
371
+
384
372
``` php
385
373
<?php
386
374
@@ -400,6 +388,7 @@ class ClassName
400
388
401
389
When the class has nothing after the ` use ` import statement, the class
402
390
closing brace MUST be on the next line after the ` use ` import statement.
391
+ For example:
403
392
404
393
``` php
405
394
<?php
@@ -414,7 +403,7 @@ class ClassName
414
403
}
415
404
```
416
405
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:
418
407
419
408
``` php
420
409
<?php
@@ -431,7 +420,7 @@ class ClassName
431
420
}
432
421
```
433
422
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
435
424
note of indentation, spacing, and new lines.
436
425
437
426
``` php
@@ -552,7 +541,7 @@ In the argument list, there MUST NOT be a space before each comma, and there
552
541
MUST be one space after each comma.
553
542
554
543
Method and function parameters with default values MUST go at the end of the argument
555
- list.
544
+ list. For example:
556
545
557
546
``` php
558
547
<?php
@@ -574,7 +563,7 @@ next line, and there MUST be only one argument per line.
574
563
575
564
When the argument list is split across multiple lines, the closing parenthesis
576
565
and opening brace MUST be placed together on their own line with one space
577
- between them.
566
+ between them. For example:
578
567
579
568
``` php
580
569
<?php
@@ -596,7 +585,7 @@ class ClassName
596
585
When you have a return type declaration present, there MUST be one space after
597
586
the colon followed by the type declaration. The colon and declaration MUST be
598
587
on the same line as the argument list closing parenthesis with no spaces between
599
- the two characters.
588
+ the two characters. For example:
600
589
601
590
``` php
602
591
<?php
@@ -623,7 +612,7 @@ class ReturnTypeVariations
623
612
```
624
613
625
614
In nullable type declarations, there MUST NOT be a space between the question mark
626
- and the type.
615
+ and the type. For example:
627
616
628
617
``` php
629
618
<?php
@@ -678,6 +667,8 @@ engine and language handles them. When present, they MUST be in the following o
678
667
679
668
All keywords MUST be on a single line, and MUST be separated by a single space.
680
669
670
+ The following is a correct example of modifier keyword usage:
671
+
681
672
``` php
682
673
<?php
683
674
@@ -711,6 +702,8 @@ after the opening parenthesis, and there MUST NOT be a space before the
711
702
closing parenthesis. In the argument list, there MUST NOT be a space before
712
703
each comma, and there MUST be one space after each comma.
713
704
705
+ The following lines show correct calls:
706
+
714
707
``` php
715
708
<?php
716
709
@@ -725,6 +718,8 @@ next line, and there MUST be only one argument per line. A single argument being
725
718
split across multiple lines (as might be the case with an anonymous function or
726
719
array) does not constitute splitting the argument list itself.
727
720
721
+ The following examples show correct argument usage.
722
+
728
723
``` php
729
724
<?php
730
725
@@ -748,14 +743,14 @@ $app->get('/hello/{name}', function ($name) use ($app) {
748
743
```
749
744
750
745
If 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:
752
747
753
748
``` php
754
749
somefunction($a, b: $b, c: 'c');
755
750
```
756
751
757
752
Method 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:
759
754
760
755
``` php
761
756
$someInstance
@@ -815,6 +810,8 @@ placed together on their own line with one space between them. Boolean
815
810
operators between conditions MUST always be at the beginning or at the end of
816
811
the line, not a mix of both.
817
812
813
+ For example:
814
+
818
815
``` php
819
816
<?php
820
817
@@ -867,6 +864,8 @@ placed together on their own line with one space between them. Boolean
867
864
operators between conditions MUST always be at the beginning or at the end of
868
865
the line, not a mix of both.
869
866
867
+ For example:
868
+
870
869
``` php
871
870
<?php
872
871
936
935
Expressions in parentheses MAY be split across multiple lines, where each
937
936
subsequent line is indented at least once. When doing so, the first condition
938
937
MUST 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:
940
939
941
940
``` php
942
941
<?php
@@ -965,7 +964,8 @@ for ($i = 0; $i < 10; $i++) {
965
964
Expressions in parentheses MAY be split across multiple lines, where each
966
965
subsequent line is indented at least once. When doing so, the first expression
967
966
MUST 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:
969
969
970
970
``` php
971
971
<?php
@@ -1023,7 +1023,7 @@ All operators not described here are left undefined.
1023
1023
### 6.1. Unary operators
1024
1024
1025
1025
The increment/decrement operators MUST NOT have any space between
1026
- the operator and operand.
1026
+ the operator and operand:
1027
1027
1028
1028
``` php
1029
1029
$i++;
@@ -1063,6 +1063,7 @@ $variable = $foo ? 'foo' : 'bar';
1063
1063
1064
1064
When the middle operand of the conditional operator is omitted, the operator
1065
1065
MUST follow the same style rules as other binary [ comparison] [ ] operators:
1066
+
1066
1067
``` php
1067
1068
$variable = $foo ?: 'bar';
1068
1069
```
@@ -1231,7 +1232,7 @@ the list of `implements` interfaces does not wrap. If the list of interfaces
1231
1232
wraps, the brace MUST be placed on the line immediately following the last
1232
1233
interface.
1233
1234
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:
1235
1236
1236
1237
``` php
1237
1238
<?php
@@ -1271,6 +1272,8 @@ Enum case declarations MUST use PascalCase capitalization. Enum case declaratio
1271
1272
Constants in Enumerations MAY use either PascalCase or UPPER_CASE capitalization. PascalCase is RECOMMENDED,
1272
1273
so that it is consistent with case declarations.
1273
1274
1275
+ The following example shows a typical valid Enum:
1276
+
1274
1277
``` php
1275
1278
enum Suit: string
1276
1279
{
@@ -1296,6 +1299,7 @@ indentation they are declared in.
1296
1299
1297
1300
The following is *** not allowed*** due to the heredoc beginning on a
1298
1301
different line than the context it's being declared in:
1302
+
1299
1303
``` php
1300
1304
$notAllowed =
1301
1305
<<<'COUNTEREXAMPLE'
@@ -1306,11 +1310,12 @@ $notAllowed =
1306
1310
COUNTEREXAMPLE;
1307
1311
```
1308
1312
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
1310
1314
declaration it's being set against.
1311
1315
1312
1316
The follow is *** not allowed*** due to the scope indention not matching the scope the
1313
1317
heredoc is declared in:
1318
+
1314
1319
``` php
1315
1320
function notAllowed()
1316
1321
{
@@ -1328,6 +1333,7 @@ it's declared in.
1328
1333
1329
1334
The following is an example of both a heredoc and a nowdoc declared in a
1330
1335
compliant way:
1336
+
1331
1337
``` php
1332
1338
function allowed()
1333
1339
{
@@ -1383,6 +1389,8 @@ MUST be placed on the next line after the last value. There MUST NOT be more
1383
1389
than one value assignment per line. Value assignments MAY use a single line
1384
1390
or multiple lines.
1385
1391
1392
+ The following example shows correct array usage:
1393
+
1386
1394
```php
1387
1395
<?php
1388
1396
0 commit comments