1 | <?php |
||
13 | trait OptionsTrait |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $options = []; |
||
19 | |||
20 | /** |
||
21 | * @param string $name |
||
22 | * |
||
23 | * @return bool |
||
24 | */ |
||
25 | protected function hasOption(string $name): bool |
||
26 | { |
||
27 | if (array_key_exists($name, $this->options)) { |
||
28 | return true; |
||
29 | } |
||
30 | |||
31 | if (!isset($this->aliases) || !isset($this->aliases[$name])) { |
||
1 ignored issue
–
show
|
|||
32 | return false; |
||
33 | } |
||
34 | |||
35 | foreach ($this->aliases[$name] as $name) { |
||
36 | return $this->hasOption($name); |
||
37 | } |
||
38 | |||
39 | return false; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $name |
||
44 | * @param mixed $default |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | protected function getOption(string $name, $default = null) |
||
68 | } |
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: