You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: general/development/policies/deprecation/index.md
+68-30
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,17 @@ In an open source project, the end use of the codebase varies. People may have c
18
18
19
19
## What is Moodle's deprecation policy?
20
20
21
-
- Deprecations should only be on the `main` branch, not on stables (exceptions may be made for some external service integrations)
21
+
- Deprecations should only be on the `main` branch, not on stables. Exceptions to this may be made in certain conditions, including:
22
+
- for some external service integrations
23
+
- where a feature is discovered to have been broken irreparably
24
+
- to address security issues
22
25
- Deprecations apply to all public APIs, classes, and files.
23
-
- Removal of a function, class, or file may only be considered after a minimum of 4 major releases since the deprecation. Example: anything deprecated in 3.2 means that it will be removed in 3.6
24
-
- All deprecations should emit debugging notices where possible
25
26
- All deprecations should be noted with an [upgrade note](../../upgradenotes.md).
27
+
- Deprecations are split into three stages:
28
+
1. Initial deprecation
29
+
2. Final deprecation
30
+
3. Removal
31
+
- All deprecations should emit debugging notices where possible
26
32
27
33
:::danger What does it mean for an API to be considered "Public"
28
34
@@ -37,17 +43,17 @@ Instead we are considering how that API feature is used. Is that API feature int
37
43
38
44
## Moodle Core deprecation process
39
45
40
-
Once it is decided that a function should be deprecated, a two-step process should be followed.
46
+
Once it is decided that a function should be deprecated, a multi-step process should be followed.
41
47
42
48
:::note
43
49
44
-
Both steps should always happen as earlier as possible in the 6-months period between major releases, so all developers will have time to adjust their code and ensure it will work in the next release. Obviously, **no changes will be allowed after code freeze**(the APIs must remain 100% unmodified after it).
50
+
These steps should always happen as early as possible in the 6-months period between major releases. This ensures that developers will have sufficient time to adjust their code and confirm compatibility with the next release. **After the code freeze, no changes will be allowed.**- APIs must remain completely unchanged.
Deprecation affects only the current main version, in other words, the deprecation only becomes effective after the next [major release](../../../releases.md).
56
+
Deprecation affects only the current `main` version, in other words, the deprecation only becomes effective after the next [major release](../../../releases.md).
51
57
52
58
- If the function is not a member of a class (in other words, it is an independent function), it should be moved, with its PHPDoc and all comments, to `lib/deprecatedlib.php`, which is included everywhere. If the function is a class member, it will need to be deprecated in its current location.
53
59
- Deprecated behat step definitions should be moved to `lib/tests/behat/behat_deprecated.php`. Steps that are part of a component should be moved to `$COMPONENT_DIRECTORY/tests/behat/behat_<COMPONENT>_deprecated.php` instead. Deprecated function should call to `behat_deprecated::deprecated_message()` proposing an alternative to the deprecated method.
@@ -58,19 +64,11 @@ Deprecation affects only the current main version, in other words, the deprecati
58
64
- Add @deprecated tag on class level PHPDoc block
59
65
- Add @deprecated tag on the PHPDoc block of all public methods
60
66
- Add debugging on all of the public methods
61
-
-Besides, if the entire class is being moved (for example, moving multiple class definitions from a monolithic file in to individual files), follow the process for [renaming classes](/docs/apis/commonfiles#dbrenamedclassesphp).
67
+
-If the entire class is being moved (for example, moving multiple class definitions from a monolithic file in to individual files), follow the process for [renaming classes](/docs/apis/commonfiles#dbrenamedclassesphp).
62
68
- A debugging message should be added to the function so that, when [developer debugging mode](https://docs.moodle.org/en/Debugging) is on, attention is drawn to the deprecation. The message should state that the function being called has been deprecated. The message should help a developer whose code currently calls the function that has gone. Tell them what they should do instead.
63
69
64
70
<Tabs>
65
71
66
-
<TabItemvalue="debugging"label="Deprecations using debugging">
67
-
68
-
```php
69
-
debugging('foobar() is deprecated. Please use foobar::blah() instead.', DEBUG_DEVELOPER);
70
-
```
71
-
72
-
</TabItem>
73
-
74
72
<TabItemvalue="core_deprecation"label="Using the \core\deprecation API from Moodle 4.4">
75
73
76
74
```php
@@ -84,6 +82,14 @@ public function foobar(int $old, array $params): array {
84
82
85
83
</TabItem>
86
84
85
+
<TabItemvalue="debugging"label="Deprecations using debugging">
86
+
87
+
```php
88
+
debugging('foobar() is deprecated. Please use foobar::blah() instead.', DEBUG_DEVELOPER);
89
+
```
90
+
91
+
</TabItem>
92
+
87
93
</Tabs>
88
94
89
95
- Unit tests that call the function should have `assertDebuggingCalled()` added to allow them to continue running.
@@ -124,49 +130,81 @@ The final deprecation policy for Moodle LMS has been updated to align more close
124
130
- Functions that have been deprecated in an LTS version (the last version within a series) will be up for final deprecation on the next major version after the next LTS release (`[X+2].0`).
125
131
126
132
<ValidExampletitle="Example">
127
-
- Functions deprecated in Moodle 4.4 (Series 4) and below will be up for final deprecation in Moodle 5.0 (the first Series 5 Moodle version).
133
+
- Functions deprecated in Moodle 4.4 (Series 4) and below will be considered for final deprecation in Moodle 5.0 (the first Series 5 Moodle version).
128
134
- Functions deprecated in Moodle 4.5 (LTS) will be up for final deprecation in Moodle 6.0 (the first release for Series 6 right after the Moodle 5.3 (LTS) release).
129
135
</ValidExample>
130
136
131
137
#### Procedure
132
138
133
-
- When a function undergoes final deprecation, all content of the function should be removed. In the skeleton that remains, an error statement should be included that indicates that the function cannot be used anymore. You can also direct developers to the new function(s) in this message.
139
+
- When a function undergoes final deprecation, all content of the function should be removed. In the skeleton that remains, an error statement should be included that indicates that the function cannot be used anymore. You should also direct developers to the new function(s) in this message.
134
140
135
141
<Tabs>
136
142
137
-
<TabItemvalue="debugging"label="Deprecations using debugging">
143
+
<TabItemvalue="core_deprecation"label="Using the \core\deprecation API from Moodle 4.4">
138
144
139
145
```php
140
-
throw new coding_exception(
141
-
'foobar() can not be used any more, please use foobar::blah'
142
-
);
146
+
#[\core\attribute\deprecated(
147
+
'foobar::blah()',
148
+
since: '4.4',
149
+
mdl: 'MDL-XXXXX',
150
+
final: true,
151
+
)]
152
+
public function foobar(int $old, array $params): array {
'foobar() cannot be used any more, please use foobar::blah'
165
+
);
155
166
```
156
167
157
168
</TabItem>
158
169
159
170
</Tabs>
160
171
161
-
-Function and Method signatures **must not change**, that is:
172
+
- Method signatures **must not change**, that is:
162
173
- keep any existing parameters; and
163
174
- keep any existing return type.
164
-
- The deprecation 'since' tag should remain as the version where the initial deprecation happened.
175
+
- Function signatures _may_ be removed, that is:
176
+
- all parameters may be removed; and
177
+
- and return type declaration may be removed.
178
+
- The deprecation 'since' tag should remain as the version where the _initial_ deprecation happened.
165
179
- Deprecated classes must be completely removed.
166
180
- The content of the PHPDoc should be removed, leaving only the `@deprecated` tag with the notice and, optionally, the replacement information. This includes all `@param`, `@return`, and other tags, as well as the description.
167
181
- External functions deprecation process is different from the standard deprecation and functions should be completely removed.
168
182
- Last but not least, every deprecation should be documented in an [upgrade note](../../upgradenotes.md)**at least** once but, **ideally**, both on the initial/immediate deprecation and also on this final deprecation/removal.
169
183
184
+
:::info Changes to Method Signatures
185
+
186
+
Previously, this policy required removing all parameter and return type declarations from method signatures. However, this caused issues with child classes due to PHP's covariance and contravariance rules.
187
+
188
+
Plugins that extended affected classes and implemented deprecated methods faced fatal errors, making it impossible to maintain a single codebase across Moodle versions.
189
+
190
+
The policy no longer permits modifying method signatures.
191
+
192
+
:::
193
+
194
+
### Step 3. Removal
195
+
196
+
#### Policy
197
+
198
+
A code removal step was added to the deprecation process in Moodle 5.0 and is aligned with the LTS release cycle.
199
+
200
+
- Any feature or functionality which went through the Step 2 (Final deprecation) process _before_ an LTS release, may be removed in the next major version _after_ the LTS release.
201
+
- Removals must be documented in an [upgrade note](../../upgradenotes.md).
202
+
203
+
<ValidExampletitle="Example">
204
+
- Functions initially deprecated in Moodle 4.4 (Series 4) and below will be considered for final deprecation in Moodle 5.0 (the first Series 5 Moodle version), and for removal in Moodle 6.0 (the first Series 6 Moodle version).
205
+
- Functions deprecated in Moodle 4.5 (LTS) will be up for final deprecation in Moodle 6.0 (the first release for Series 6 right after the Moodle 5.3 (LTS) release), and for removal in Moodle 7.0 (the first Series 7 Moodle version).
206
+
</ValidExample>
207
+
170
208
## Parameters deprecation
171
209
172
210
Whilst it is possible to deprecate individual method parameters, care must be taken in doing so.
0 commit comments