$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array
definition as it guarantees a stable state of the code.
Let’s take a look at an example:
foreach($collectionas$item){$myArray['foo']=$item->getFoo();if($item->hasBar()){$myArray['bar']=$item->getBar();}// do something with $myArray}
As you can see in this example, the array $myArray is initialized the first
time when the foreach loop is entered. You can also see that the value of the
bar key is only written conditionally; thus, its value might result from a
previous iteration.
This might or might not be intended. To make your intention clear, your code
more readible and to avoid accidental bugs, we recommend to add an explicit
initialization $myArray=array() either outside or inside the foreach loop.
Loading history...
11
'aliases' => ['cmt'],
12
'description' => 'Show the content moderation as a table.',
13
];
14
15
$items['como-graphviz'] = [
16
'aliases' => ['cmg'],
17
'description' => 'Show the content moderation as a Graphviz DOT file.',
18
'arguments' => [
19
'workflow' => 'The machine name of a workflow',
20
]
21
];
22
23
$items['qa-workflows-list'] = [
24
'aliases' => ['qawl'],
25
'description' => 'Show a summary of available workflows',
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.