|
28 | 28 | * 2. The function has no side effects (no mutation of non-local variables, |
29 | 29 | * mutable reference arguments or input/output streams). |
30 | 30 | * |
31 | | - * In PHP, that means a pure function MUST NOT: |
| 31 | + * In PHP, that means a pure function: |
32 | 32 | * |
33 | | - * 1. Use or modify any global variable. |
34 | | - * 2. Perform any IO operations, even read-only ones. |
35 | | - * 3. Modify any property of an object provided to it as an argument, |
36 | | - * even transitively. |
37 | | - * 4. Read from an object property on the same object unless that property |
38 | | - * is `readonly`. |
39 | | - * 5. Accept a parameter by reference. |
40 | | - * 6. Call any function that is not also marked "pure." (It may invoke a |
41 | | - * callable passed to it as an explicit argument.) |
| 33 | + * 1. MUST NOT use or modify any global variable. |
| 34 | + * 2. MIST NOT perform any IO operations, even read-only ones. |
| 35 | + * 3. MUST NOT modify any property of an object provided to it as an |
| 36 | + * argument, even transitively. |
| 37 | + * 4. MUST NOT read from an object property on the same object unless |
| 38 | + * that property is `readonly`. |
| 39 | + * 5. MUST NOT accept a parameter by reference. |
| 40 | + * 6. MUST NOT call any function that is not also marked "pure." (It |
| 41 | + * may invoke a callable passed to it as an explicit argument.) |
42 | 42 | * |
43 | 43 | * ## When should the attribute be applied |
44 | 44 | * |
|
48 | 48 | * If this attribute is placed on a method in an interface, it means that all |
49 | 49 | * implementations of that method MUST themselves be marked pure. |
50 | 50 | * |
51 | | - * Static analysis tools SHOULD |
52 | | - * - Verify that the function indeed meets the rules above, and treat it as |
53 | | - * an error if not. |
| 51 | + * Static analysis tools |
| 52 | + * - SHOULD verify that the function indeed meets the rules above, |
| 53 | + * and treat it as an error if not. |
54 | 54 | * |
55 | | - * Static analysis tools MUST |
56 | | - * - Treat PHP standard library functions that conform to these rules as pure. |
57 | | - * As an example, `strtolower()` is pure. `sort()` is not. |
58 | | - * - Flag as an error any function that is marked pure but is demonstrably not. |
59 | | - * - Treat any method implementing an interface method marked pure as pure. |
| 55 | + * Static analysis tools |
| 56 | + * - MUST treat PHP standard library functions that conform to these |
| 57 | + * rules as pure. As an example, `strtolower()` is pure. `sort()` |
| 58 | + * is not. |
| 59 | + * - MUST flag as an error any function that is marked pure but is |
| 60 | + * demonstrably not. |
| 61 | + * - MUST treat any method implementing an interface method marked |
| 62 | + * pure as pure. |
60 | 63 | * |
61 | | - * Optimization tools and pre-compilation tools MAY: |
62 | | - * - Implement optimizations based on the knowledge that a function is pure. |
63 | | - * For example, they may safely cache its results indefinitely, or inline its |
64 | | - * code into another routine. |
| 64 | + * Optimization tools and pre-compilation tools: |
| 65 | + * - MAY implement optimizations based on the knowledge that a function |
| 66 | + * is pure. For example, they may safely cache its results indefinitely, |
| 67 | + * or inline its code into another routine. |
65 | 68 | * |
66 | 69 | */ |
67 | 70 | #[\Attribute(\Attribute::TARGET_FUNCTION | \Attribute::TARGET_METHOD)] |
|
0 commit comments