-
Bug
-
Resolution: Fixed
-
Low
-
None
Since 29th Dec 2022, this rule applies:
- Short array syntax should be used for all arrays, in all uses. This includes:
$myarray = [];
$myarray = ['some', 'value'];
$myarray = (object) [];
$myarray = (object) ['some', 'value'];
$myarray = [
'some' => 'value',
];
$myarray = (object) [
'some' => 'value',
];
- The use of the array() syntax is not allowed in new code. The existing code will not be bulk-updated at this time. Scope-specific changes (methods, classes) will be allowed in related issues.
Voting
Timeframe
Voting for this issue opens immediately (Wednesday 21st December 2022) and will remain open until Thursday 29th December 2022 at 12pm UTC.
Voting options
The following options are suggested for voting:
Option A
Short array syntax should be used for all arrays, in all uses. This includes:
$myarray = [];
|
$myarray = ['some', 'value'];
|
$myarray (object) [];
|
$myarray (object) ['some', 'value'];
|
$myarray = [
|
'some' => 'value',
|
];
|
$myarray = (object) [
|
'some' => 'value',
|
];
|
The use of the array() syntax is not allowed in new code. Existing code will not be bulk-updated at this time. Scope-specific changes (methods, classes) will be allowed in related issues.
Added to the existing Arrays section
## Arrays
|
|
{quote}
|
### Array syntax
|
|
When declaring new arrays, the Short Array Syntax should be used.
|
|
<ValidExample>
|
|
```php
|
$myarray = [];
|
$myarray = ['some', 'value'];
|
$myarray (object) [];
|
$myarray (object) ['some', 'value'];
|
$myarray = [
|
'some' => 'value',
|
];
|
$myarray = (object) [
|
'some' => 'value',
|
];
|
```
|
|
</ValidExample>
|
|
The Long Array Syntax should not be used for new code, _but may be used_ where it matches surrounding code.
|
|
<InvalidExample>
|
|
```php
|
$myarray = array();
|
$myarray = array('some', 'value');
|
$myarray (object) array();
|
$myarray (object) array('some', 'value');
|
$myarray = array(
|
'some' => 'value',
|
);
|
$myarray = (object) array(
|
'some' => 'value',
|
);
|
```
|
|
</InvalidExample>
|
{quote}
|
Option B
Long array syntax should used for all arrays, in all uses. This includes:
$myarray = array();
|
$myarray = array('some', 'value');
|
$myarray (object) array();
|
$myarray (object) array('some', 'value');
|
$myarray = array(
|
'some' => 'value',
|
);
|
$myarray = (object) array(
|
'some' => 'value',
|
);
|
The use of the [] syntax is not allowed in new code. Existing code will not be bulk-updated. Scope-specific changes (methods, classes) will be allowed in related issues.
Added to the existing Arrays section
## Arrays
|
|
{quote}
|
### Array syntax
|
|
When declaring new arrays, the Short Array Syntax should be used.
|
|
<ValidExample>
|
$myarray = array();
|
$myarray = array('some', 'value');
|
$myarray (object) array();
|
$myarray (object) array('some', 'value');
|
$myarray = array(
|
'some' => 'value',
|
);
|
$myarray = (object) array(
|
'some' => 'value',
|
);
|
</ValidExample>
|
|
The Long Array Syntax should not be used for new code, _but may be used_ where it matches surrounding code.
|
|
<InvalidExample>
|
$myarray = [];
|
$myarray = ['some', 'value'];
|
$myarray (object) [];
|
$myarray (object) ['some', 'value'];
|
$myarray = [
|
'some' => 'value',
|
];
|
$myarray = (object) [
|
'some' => 'value',
|
];
|
</InvalidExample>
|
|
{quote}
|
Option C
No change to existing coding style. That is to say that both Short, and Long Array Syntax are both permitted, though their use should be consistent with surrounding code.
- Discovered while testing
-
MDL-55833 Non-anonymous feedback does not show in complete report
- Closed
- links to