1 | <?php |
||
5 | trait HasCustomProperties |
||
6 | { |
||
7 | public function hasCustomProperty(string $propertyName): bool |
||
11 | |||
12 | /** |
||
13 | * Get the value of custom property with the given name. |
||
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 | } |
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: