1 | <?php |
||
5 | trait Generators |
||
6 | { |
||
7 | /** |
||
8 | * Generate a random string. |
||
9 | * |
||
10 | * @return string |
||
11 | */ |
||
12 | 8 | protected function generate() |
|
18 | |||
19 | /** |
||
20 | * Generate a ramdom integer. |
||
21 | * |
||
22 | * @return int |
||
23 | */ |
||
24 | 1 | protected function generateInteger() |
|
28 | |||
29 | /** |
||
30 | * Generate a random string. |
||
31 | * |
||
32 | * @param \Closure $generator |
||
33 | * @return mixed |
||
34 | */ |
||
35 | 8 | protected function generateString($generator) |
|
45 | |||
46 | /** |
||
47 | * Get the alpha generator. |
||
48 | * |
||
49 | * @return mixed |
||
50 | */ |
||
51 | protected function getAlphaGenerator() |
||
57 | |||
58 | /** |
||
59 | * Get the alpha generator. |
||
60 | * |
||
61 | * @return mixed |
||
62 | */ |
||
63 | protected function getNumericGenerator() |
||
69 | |||
70 | /** |
||
71 | * Generate a random string. |
||
72 | * |
||
73 | * @return int|string |
||
74 | */ |
||
75 | 7 | protected function generateAlpha() |
|
79 | |||
80 | /** |
||
81 | * Generate a numeric random value. |
||
82 | * |
||
83 | * @return int|string |
||
84 | */ |
||
85 | 3 | protected function generateNumeric() |
|
93 | } |
||
94 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: