| 1 | <?php |
||
| 7 | trait HasCustomProperties |
||
| 8 | { |
||
| 9 | public function hasCustomProperty(string $propertyName): bool |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param string $propertyName |
||
| 16 | * @param mixed $default |
||
| 17 | * |
||
| 18 | * @return mixed |
||
| 19 | */ |
||
| 20 | public function getCustomProperty(string $propertyName, $default = null) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $name |
||
| 27 | * @param mixed $value |
||
| 28 | * |
||
| 29 | * @return $this |
||
| 30 | */ |
||
| 31 | public function setCustomProperty(string $name, $value) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $name |
||
| 44 | * |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | public function forgetCustomProperty(string $name) |
||
| 57 | } |
||
| 58 |
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: