$dados was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dados = 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...
14
$dados['usuario_id'] = $usuario_id;
15
$dados['nome_variacao'] = $variacao['variacao'];
16
$dados['estoque'] = $variacao['estoque'];
17
$dados['ativo'] = 1;
18
19
$this->Variacao->save($dados);
20
}
21
22
return true;
23
}
24
25
public function desativar_variacoes($id) {
26
if (empty($id)) {
27
return false;
28
}
29
30
$dados = array ('ativo' => '0');
31
$parametros = array ('produto_id' => $id);
32
33
if (!$this->Variacao->updateAll($dados, $parametros)) {
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.