| 1 | <?php |
||
| 8 | trait MagicSetters |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Dynamically set attributes on the entity. |
||
| 12 | * |
||
| 13 | * @param string $key |
||
| 14 | * @param mixed $value |
||
| 15 | * @return void |
||
| 16 | */ |
||
| 17 | public function __set($key, $value) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Unset an attribute on the entity. |
||
| 24 | * |
||
| 25 | * @param string $key |
||
| 26 | * @return void |
||
| 27 | */ |
||
| 28 | public function __unset($key) |
||
| 32 | |||
| 33 | |||
| 34 | } |
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: