1 | <?php |
||
7 | trait HasCustomProperties |
||
8 | { |
||
9 | 5 | public function __construct(array $attributes = []) |
|
14 | |||
15 | 1 | public function forgetCustomProperty(string $name): self |
|
23 | |||
24 | /** |
||
25 | * Get the value of custom property with the given name. |
||
26 | * |
||
27 | * @param string $propertyName |
||
28 | * @param mixed $default |
||
29 | * |
||
30 | * @return mixed |
||
31 | */ |
||
32 | 1 | public function getCustomProperty(string $propertyName, $default = null) |
|
36 | |||
37 | /* |
||
38 | * Determine if the model item has a custom property with the given name. |
||
39 | */ |
||
40 | 1 | public function hasCustomProperty(string $propertyName): bool |
|
44 | |||
45 | /** |
||
46 | * @param string $name |
||
47 | * @param mixed $value |
||
48 | * |
||
49 | * @return $this |
||
50 | */ |
||
51 | 5 | public function setCustomProperty(string $name, $value): self |
|
59 | } |
||
60 |
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: