1 | <?php |
||
7 | trait Tables |
||
8 | { |
||
9 | /** |
||
10 | * Indicate that the table needs to be created. |
||
11 | * |
||
12 | * @param array $options |
||
13 | * @return Fluent |
||
14 | */ |
||
15 | public function create($options = []) |
||
23 | |||
24 | /** |
||
25 | * Determine if the blueprint has a create command. |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | protected function creating() |
||
35 | |||
36 | public function executeCreateCommand($command) |
||
56 | |||
57 | /** |
||
58 | * Alias for getCollection. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getTable() |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Rename the table to a given name. |
||
70 | * |
||
71 | * @param string $to |
||
72 | * @return Fluent |
||
73 | */ |
||
74 | public function rename($to) |
||
78 | |||
79 | |||
80 | /** |
||
81 | * Indicate that the table should be dropped. |
||
82 | * |
||
83 | * @return Fluent |
||
84 | */ |
||
85 | public function drop() |
||
92 | |||
93 | /** |
||
94 | * Indicate that the table should be dropped if it exists. |
||
95 | * |
||
96 | * @return Fluent |
||
97 | */ |
||
98 | public function dropIfExists() |
||
105 | |||
106 | } |
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.