1 | <?php |
||
7 | class Builder extends IlluminateBuilder |
||
8 | { |
||
9 | /** |
||
10 | * The methods that should be returned from query builder. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $passthru = [ |
||
15 | 'insert', 'insertOrIgnore', 'insertGetId', 'insertUsing', 'getBindings', 'toSql', 'dump', 'dd', |
||
16 | 'exists', 'doesntExist', 'count', 'min', 'max', 'avg', 'average', 'sum', 'getConnection', |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * Update a record in the database. |
||
21 | * |
||
22 | * @param array $values |
||
23 | * @return int |
||
24 | */ |
||
25 | public function update(array $values) |
||
29 | |||
30 | /** |
||
31 | * Update a record in the database. |
||
32 | * |
||
33 | * @param array $values |
||
34 | * @return int |
||
35 | */ |
||
36 | public function insert(array $values) |
||
67 | |||
68 | /** |
||
69 | * Add the "updated at" column to an array of values. |
||
70 | * |
||
71 | * @param array $values |
||
72 | * @return array |
||
73 | */ |
||
74 | protected function updateTimestamps(array $values) |
||
95 | } |
||
96 |
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.