1 | <?php |
||
57 | class Profile extends BaseBlameableModel |
||
58 | { |
||
59 | public $createdByAttribute = 'guid'; |
||
60 | |||
61 | // The host of Profile is only permitted to modify it. |
||
62 | public $updatedByAttribute = false; |
||
63 | |||
64 | // Profile do not have its identifier. |
||
65 | public $idAttribute = false; |
||
66 | |||
67 | // Profile do not need to record IP address. |
||
68 | public $enableIP = 0; |
||
69 | |||
70 | /** |
||
71 | * @var string Specify the nickname as the content attribute. |
||
72 | */ |
||
73 | public $contentAttribute = 'nickname'; |
||
74 | |||
75 | const SCENARIO_UPDATE = 'update'; |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | public function attributeLabels() |
||
96 | |||
97 | /** |
||
98 | * Get rules associated with individual sign attribute. |
||
99 | * You can override this method if current rules do not satisfy your needs. |
||
100 | * If you do not use individual sign attribute, please override this method and return empty array. |
||
101 | * @return array Rules associated with individual sign. |
||
102 | */ |
||
103 | 16 | public function getIndividualSignRules() |
|
110 | |||
111 | /** |
||
112 | * Get rules associated with name attribute. |
||
113 | * You can override this method if current rules do not satisfy your needs. |
||
114 | * If you do not use name attribute, please override this method and return empty array. |
||
115 | * @return array Rules associated with name. |
||
116 | */ |
||
117 | 16 | public function getNameRules() |
|
124 | |||
125 | const GENDER_UNSPECIFIED = 0xffff; |
||
126 | const GENDER_MALE = 1; |
||
127 | const GENDER_FEMALE = 2; |
||
128 | |||
129 | public static $genders = [ |
||
130 | self::GENDER_MALE => 'Male', |
||
131 | self::GENDER_FEMALE => 'Female', |
||
132 | ]; |
||
133 | |||
134 | /** |
||
135 | * Get rules associated with gender attribute. |
||
136 | * You can override this method if current rules do not satisfy your needs. |
||
137 | * If you do not use gender attribute, please override this method and return empty array. |
||
138 | * @return array Rules associated with gender. |
||
139 | */ |
||
140 | 16 | public function getGenderRules() |
|
147 | |||
148 | public static function getGenderDesc($gender = null) |
||
155 | |||
156 | public static function getGenderDescs() |
||
164 | |||
165 | /** |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public static function getGenderDescsWithEmpty() |
||
176 | |||
177 | /** |
||
178 | * @return array |
||
179 | */ |
||
180 | 16 | public function getGravatarRules() |
|
189 | |||
190 | /** |
||
191 | * @return array |
||
192 | */ |
||
193 | 16 | public function getTimezoneRules() |
|
200 | |||
201 | /** |
||
202 | * @inheritdoc |
||
203 | */ |
||
204 | 16 | public function rules() |
|
213 | |||
214 | /** |
||
215 | * @inheritdoc |
||
216 | */ |
||
217 | 18 | public static function tableName() |
|
221 | |||
222 | /** |
||
223 | * @return array |
||
224 | */ |
||
225 | 16 | public function scenarios() |
|
231 | |||
232 | /** |
||
233 | * @inheritdoc |
||
234 | */ |
||
235 | 18 | public function init() |
|
240 | |||
241 | /** |
||
242 | * @var string |
||
243 | */ |
||
244 | public $cacheTagPrefix = 'tag_user_profile_'; |
||
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | */ |
||
249 | public function getCacheTag() |
||
253 | |||
254 | /** |
||
255 | * @param Event $event |
||
256 | */ |
||
257 | public function onInvalidTags($event) |
||
263 | } |
||
264 |
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.