| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 13 | 
| Code Lines | 10 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 5 | 	public function salvar_lancamento($id_venda, $dados, $valor_total, $id_usuario) { | ||
| 6 | $lancamento['venda_id'] = $id_venda; | ||
|  | |||
| 7 | $lancamento['valor'] = $valor_total; | ||
| 8 | $lancamento['valor_pago'] = $valor_total; | ||
| 9 | 		$lancamento['data_pgt']   = date('Y-m-d'); | ||
| 10 | $lancamento['ativo'] = 1; | ||
| 11 | $lancamento['usuario_id'] = $id_usuario; | ||
| 12 | $lancamento['forma_pagamento'] = $dados['forma_pagamento']; | ||
| 13 | |||
| 14 | $this->LancamentoVenda->save($lancamento); | ||
| 15 | |||
| 16 | return true; | ||
| 17 | } | ||
| 18 | |||
| 64 | } | 
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.