@@ -477,112 +477,7 @@ class ClassName
477477}
478478```
479479
480- ### 4.4 Property Hooks
481-
482- Object properties may also include hooks, which have a number of syntactic options.
483-
484- If there is only one hook implementation, and that hook implementation itself uses
485- the short-hook syntax, then the hook declaration MAY be listed entirely inline. The hook
486- name MUST be separated from the opening brace and the arrow operator by a single
487- space, and the semicolon ending of the hook MUST be separated from the cosing brace
488- by a single space. For example:
489-
490- ``` php
491- class Example
492- {
493- public string $myName { get => __CLASS__; }
494-
495- public string $newName { set => ucfirst($value); }
496- }
497- ```
498-
499- If those two criteria are not met, then the hook block MUST be spread across multiple lines:
500-
501- ``` php
502- class Example
503- {
504- public string $myName {
505- get => __CLASS__;
506- }
507-
508- public string $newName {
509- set => ucfirst($value);
510- }
511- }
512- ```
513-
514- When using the multi-line form, the opening brace MUST be on the same line as the property and
515- the closing brace MUST be on its own line, with the body indented one level.
516-
517- The ` => ` operator MUST have a single space on either side.
518-
519- If multiple hooks are declared, they MUST be separated by at least a single line break. They
520- MAY be separated by an additional blank line to aid readability.
521-
522- If the property includes a default value, there MUST be a single space between the default value
523- and the opening brace.
524-
525- ``` php
526- class Example
527- {
528- public string $newName = 'Me' {
529- set => ucfirst($value);
530- }
531- }
532- ```
533-
534- If a hook is using its multi-line form, the opening brace MUST be on the same line as the hook
535- name, and the closing brace MUST be on its own line. The body MUST be indented one level.
536-
537- ``` php
538- class Example
539- {
540- public string $newName = 'Me' {
541- set {
542- if (strlen($value) < 3) {
543- throw new \Exception('Too short');
544- }
545- $this->newName = ucfirst($value);
546- }
547- }
548- }
549- ```
550-
551- For a ` set ` hook, if the argument name and type do not need to be redefined, then they MAY be omitted.
552-
553- Property hooks MAY also be defined in constructor-promoted properties. However, they
554- MUST be only a single hook, with a short-syntax body, defined on a single line as above.
555- If those criteria are not met, then the promoted property MUST NOT have any hooks defined
556- inline, and SHOULD instead be defined as normal property and not promoted.
557-
558- ``` php
559- class Example
560- {
561- public function __construct(
562- public string $name { set => ucfirst($value; }
563- ) {}
564- }
565- ```
566-
567- The following is *** not allowed*** due to the hook being too complex:
568-
569- ``` php
570- class Example
571- {
572- public function __construct(
573- public string $name {
574- set {
575- if (strlen($value) < 3) {
576- throw new \Exception('Too short');
577- }
578- $this->newName = ucfirst($value);
579- }
580- }
581- ) {}
582- }
583- ```
584-
585- ### 4.5 Methods and Functions
480+ ### 4.4 Methods and Functions
586481
587482Visibility MUST be declared on all methods.
588483
@@ -647,7 +542,7 @@ class Point
647542}
648543```
649544
650- ### 4.6 Method and Function Parameters
545+ ### 4.5 Method and Function Parameters
651546
652547In the argument list, there MUST NOT be a space before each comma, and there
653548MUST be one space after each comma.
@@ -765,7 +660,7 @@ public function process(string $algorithm, &...$parts)
765660}
766661```
767662
768- ### 4.7 Modifier Keywords
663+ ### 4.6 Modifier Keywords
769664
770665Classes, properties, and methods have numerous keyword modifiers that alter how the
771666engine and language handles them. When present, they MUST be in the following order:
@@ -806,7 +701,7 @@ readonly class ValueObject
806701}
807702```
808703
809- ### 4.8 Method and Function Calls
704+ ### 4.7 Method and Function Calls
810705
811706When making a method or function call, there MUST NOT be a space between the
812707method or function name and the opening parenthesis, there MUST NOT be a space
@@ -871,12 +766,118 @@ $someInstance
871766 ->run();
872767```
873768
874- ### 4.9 Function Callable References
769+ ### 4.8 Function Callable References
875770
876771A function or method may be referenced in a way that creates a closure out of it, by providing ` ... ` in place of arguments.
877772
878773If so, the ` ... ` MUST NOT include any whitespace before or after. That is, the correct format is ` foo(...) ` .
879774
775+
776+ ### 4.9 Property Hooks
777+
778+ Object properties may also include hooks, which have a number of syntactic options.
779+
780+ If there is only one hook implementation, and that hook implementation itself uses
781+ the short-hook syntax, then the hook declaration MAY be listed entirely inline. The hook
782+ name MUST be separated from the opening brace and the arrow operator by a single
783+ space, and the semicolon ending of the hook MUST be separated from the closing brace
784+ by a single space. For example:
785+
786+ ``` php
787+ class Example
788+ {
789+ public string $myName { get => __CLASS__; }
790+
791+ public string $newName { set => ucfirst($value); }
792+ }
793+ ```
794+
795+ If those two criteria are not met, then the hook block MUST be spread across multiple lines:
796+
797+ ``` php
798+ class Example
799+ {
800+ public string $myName {
801+ get => __CLASS__;
802+ }
803+
804+ public string $newName {
805+ set => ucfirst($value);
806+ }
807+ }
808+ ```
809+
810+ When using the multi-line form, the opening brace MUST be on the same line as the property and
811+ the closing brace MUST be on its own line, with the body indented one level.
812+
813+ The ` => ` operator MUST have a single space on either side.
814+
815+ If multiple hooks are declared, they MUST be separated by at least a single line break. They
816+ MAY be separated by an additional blank line to aid readability.
817+
818+ If the property includes a default value, there MUST be a single space between the default value
819+ and the opening brace.
820+
821+ ``` php
822+ class Example
823+ {
824+ public string $newName = 'Me' {
825+ set => ucfirst($value);
826+ }
827+ }
828+ ```
829+
830+ If a hook is using its multi-line form, the opening brace MUST be on the same line as the hook
831+ name, and the closing brace MUST be on its own line. The body MUST be indented one level.
832+
833+ ``` php
834+ class Example
835+ {
836+ public string $newName = 'Me' {
837+ set {
838+ if (strlen($value) < 3) {
839+ throw new \Exception('Too short');
840+ }
841+ $this->newName = ucfirst($value);
842+ }
843+ }
844+ }
845+ ```
846+
847+ For a ` set ` hook, if the argument name and type do not need to be redefined, then they MAY be omitted.
848+
849+ Property hooks MAY also be defined in constructor-promoted properties. However, they
850+ MUST be only a single hook, with a short-syntax body, defined on a single line as above.
851+ If those criteria are not met, then the promoted property MUST NOT have any hooks defined
852+ inline, and SHOULD instead be defined as normal property and not promoted.
853+
854+ ``` php
855+ class Example
856+ {
857+ public function __construct(
858+ public string $name { set => ucfirst($value; }
859+ ) {}
860+ }
861+ ```
862+
863+ The following is *** not allowed*** due to the hook being too complex:
864+
865+ ``` php
866+ class Example
867+ {
868+ public function __construct(
869+ public string $name {
870+ set {
871+ if (strlen($value) < 3) {
872+ throw new \Exception('Too short');
873+ }
874+ $this->newName = ucfirst($value);
875+ }
876+ }
877+ ) {}
878+ }
879+ ```
880+
880881## 5. Control Structures
881882
882883The general style rules for control structures are as follows:
0 commit comments