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/codingstyle/index.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1159,6 +1159,37 @@ Magic methods are heavily discouraged, justification will be required when used.
1159
1159
1160
1160
(See [MDL-52634](https://moodle.atlassian.net/browse/MDL-52634) for discussion of rationale)
1161
1161
1162
+
### Using arrays for options as arguments
1163
+
1164
+
All arguments to a function should be explicitly listed out and defined with a type. Using arrays like this can result in error as the types are not enforced as well as leading to poor documentation of the function
1165
+
1166
+
<InvalidExample>
1167
+
```php
1168
+
public function badfunction(
1169
+
string $text,
1170
+
context $context = null,
1171
+
array $options = [],
1172
+
): string;
1173
+
</InvalidExample>
1174
+
1175
+
If arguments are optional, then they should be marked appropriately as optional with a default value.
1176
+
<ValidExample>
1177
+
function goodfunction(
1178
+
string $text,
1179
+
?context $context = null,
1180
+
bool $trusted = false,
1181
+
?bool $clean = null,
1182
+
bool $filter = true,
1183
+
bool $para = true,
1184
+
bool $newlines = true,
1185
+
bool $overflowdiv = false,
1186
+
bool $blanktarget = false,
1187
+
bool $allowid = false,
1188
+
): string;
1189
+
</ValidExample>
1190
+
1191
+
If there was a very good reason, then the use of an array could be considered. But it is strongly encouraged that all parameters be explict and typed.
1192
+
1162
1193
## Control statements
1163
1194
1164
1195
In general, use white space liberally between lines to add clarity.
0 commit comments