1 | <?php |
||
25 | trait MetaTrait |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Store the guid of blame. |
||
30 | * @var string |
||
31 | */ |
||
32 | 2 | public function behaviors() |
|
36 | |||
37 | public function getKey() |
||
41 | |||
42 | public function setKey($key) |
||
46 | |||
47 | public function getValue() |
||
51 | |||
52 | public function setValue($value) |
||
56 | |||
57 | /** |
||
58 | * Skip all behaviors of parent class. |
||
59 | * @return array |
||
60 | */ |
||
61 | 2 | public function getMetaBehaviors() |
|
65 | |||
66 | /** |
||
67 | * Get meta value by specified key. If key doesn't exist, null will be given. |
||
68 | * @param string $key meta key. |
||
69 | * @return string meta value. |
||
70 | */ |
||
71 | 2 | public static function get($key) |
|
80 | |||
81 | /** |
||
82 | * Get meta values by specified keys. If one of keys doesn't exists, it will |
||
83 | * not appear in return array. |
||
84 | * @param string[] $keys |
||
85 | * @return array meta key-value pairs. |
||
86 | */ |
||
87 | 2 | public static function gets($keys = null) |
|
108 | |||
109 | /** |
||
110 | * Set value. |
||
111 | * @param string $key |
||
112 | * @param string $value |
||
113 | * @param string $createdBy |
||
114 | * @return int |
||
115 | */ |
||
116 | 2 | public static function set($key, $value = null, $createdBy = null) |
|
132 | |||
133 | /** |
||
134 | * Set values in batch. |
||
135 | * @param array $keys meta key-value pairs. |
||
136 | * @param string $createdBy |
||
137 | * @return false if $keys is not an array. |
||
138 | */ |
||
139 | 2 | public static function sets($keys, $createdBy = null) |
|
148 | |||
149 | 2 | public static function remove($key) |
|
153 | } |
||
154 |
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: